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];
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment