Instructions:
Input
1. First integer
2. Second integer
3. Third integer
Output
The first three lines will contain message prompts to input the 3 integers.
The last line contains the three integers in ascending order.
Enter the first integer: 6
Enter the second integer: 1
Enter the third integer: 3
1 3 6
#include <stdio.h>
int main()
{
int i1, i2, i3;
printf("Enter first integer: ");
scanf("%d", &i1);
printf("Enter second integer: ");
scanf("%d", &i2);
printf("Enter third integer: ");
scanf("%d", &i3);
if (i1 <= i2 && i2 <= i3) {
printf("%d %d %d\n", i1, i2, i3);
}
else if (i1 <= i3 && i3 <= i2) {
printf("%d %d %d\n", i1, i3, i2);
}
else if (i2 <= i1 && i1 <= i3) {
printf("%d %d %d\n", i2, i1, i3);
}
else if (i2 <= i3 && i3 <= i1) {
printf("%d %d %d\n", i2, i3, i1);
}
else if (i3 <= i1 && i1 <= i2) {
printf("%d %d %d\n", i3, i1, i2);
}
else { /* i3 <= i2 <= i1 */
printf("%d %d %d\n", i3, i2, i1);
}
return 0;
}
Comments
Leave a comment