Answer to Question #269296 in C for Neil

Question #269296

Instructions:

  1. Input three integers.
  2. Print the integers in ascending order using your knowledge on conditional statements.


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
1
Expert's answer
2021-11-21T13:55:53-0500
#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;
}

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