Sort Three Numbers - program reads in three Integers and displays them in ascending order.

How to write a C Program to reads in three Integers and displays them in ascending order in C Programming Language ?

Let's read on the keyboard three integers. Write them out in ascending order!

This program reads in three Integers and displays them in ascending order.

Solution For C Program:

/* Olvassunk be a billentyûzetrõl három egész számot. Írjuk ki õket növekvõ sorrendben! */

#include <stdio.h>

int main(){

int a;
int b;
int c;

scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);

printf("%d %d %d\n\n\n", a, b, c);

if(a==b && a==c ){
    printf(" %d %d %d", a, b, c);
    return 0;
}


if(a==b){
    if(a<c){
        printf(" %d %d %d", a, b, c);
    }
    else
        printf(" %d %d %d", c, a, b);
}

if(a==c){
    if(a<b){
        printf(" %d %d %d", a, c, b);
    }
    else
        printf(" %d %d %d", b, a, a);
}

if(b==c){
    if(b<a){
        printf(" %d %d %d", b, c, a);
    }
    else
        printf(" %d %d %d", a, b, c);
}





if(a<b && a<c){
    if(b<c){
        printf(" %d %d %d", a, b,c);
    }
    if(c<b){
        printf(" %d %d %d", a, c, b);
    }
}

if(b<a && b<c){
    if(a<c){
        printf(" %d %d %d", b, a, c);
    }
    if(c<a){
        printf(" %d %d %d", b, c, a);
    }
}

if(c<a && c<b){
    if(a<b){
        printf(" %d %d %d", c, a, b);
    }
    if(b<a){
        printf(" %d %d %d", c, b, a);
    }
}

return 0;}


Learn More :