For people who know C++ or have worked with C++, I need some help. How would I write this into a program:
Use functional decomposition to write a C++ program that determines the median of three input numbers. The median is the middle numbers when the three are arranged in order. However, the user can input the values in any order, so your program must determine which value is between the other two. For example, if the user enters: 41.52, 27.18, 96.03 then the program would input: "The median of 41.52, 27.18, and 96.03 is 41.52."
Please people help me. Even some ideas would help. I would really appreciate it.
Please people, I need some C++ Help.?
It's very simple, you ca nuse array for enter these number and sort them with a simple algorithm
void main()
{
float ar[3],i,j,t;
coutt%26lt;%26lt;"\n Enter the number";
for(i=0;i%26lt;3;i++)
cin%26gt;%26gt;ar[i];
for(i=0;i%26lt;3;i++)
{
for(j=i+1;j%26lt;3;j++)
{
if(a[i]%26gt;a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
cout%26lt;%26lt;"\Median is"%26lt;%26lt;a[1];
}
Note: This program works for three number only;
for more info visit http://codesbyshariq.blogspot.com
Reply:Does not look easy. May be you can ask it to some C++ expert at websites like http://askexpert.info/
Reply:Well, I am not a C++ programmer, but I am a programmer, and I think that in order to do this, there are a couple of different approaches you could take. If the number of inputs is fixed, and will always be three, you could assign each of the numbers to an array, sort the array, then simply return the second element (index of 1). You could also run through a series of 'if...then' statements, assigning each value to a specified variable, thereby doing a brute force sort. Good luck : )
wedding
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment