Answer to Question #14466 in Action Script | Flash | Flex | ColdFusion for angela

Question #14466
Write a C++ program that declares three variables minNum, midNum and maxNum to receive three integers read from the keyboard. The inputs are unsorted and can be read into the three variables in any order, for example, the first read number in minNum may not be the smallest. However, your program should then sort the three numbers to ensure minNum ≤ midNum ≤ maxNum and display them in this order.
1
Expert's answer
2012-09-13T11:56:27-0400
#include<stdio.h>
#include <conio.h>
#include <math.h>
int main()
{

int minNum, midNum,maxNum;
int arrayofnumbers[3];
int max,min;
printf("Enter the number 1: ");
scanf("%d",&minNum);
printf("Enter the number 2: ");
scanf("%d",&midNum);
printf("Enter the number 3: ");
scanf("%d",&maxNum);
arrayofnumbers[0]=minNum;
arrayofnumbers[1]=midNum;
arrayofnumbers[2]=maxNum;
max=arrayofnumbers[0];
min=arrayofnumbers[0];
for(int i=0;i<3;i++){
if(max<arrayofnumbers[i]){
max=arrayofnumbers[i];
}
}
for(int i=0;i<3;i++){
if(min>arrayofnumbers[i]){
min=arrayofnumbers[i];

}
}
maxNum=max;
minNum=min;
printf("minNum <= midNum <= maxNum:
");
printf("%d <= %d <= %d",minNum,midNum,maxNum);
getch();
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS