Follow This Blog For more... 😊

Program to accept three numbers from user and print them in ascending and descending order.| Using C language| very Basic| C Program series 11|

👨‍💻Program to accept three numbers and print them in ascending and descending order.

Code:


    //Program to accept three numbers from the user and print them in ascending and descending order.
   
    #include<stdio.h>
   
    main()
    {
        printf("Program to accept three numbers from user and print them in ascending and descending order.\n\n");
       
        int a,b,c;
       
        printf("Enter the value of a:");
        scanf("%d",&a);
        printf("Enter the value of b:");
        scanf("%d",&b);
        printf("Enter the value of c:");
        scanf("%d",&c);
       
        if(a>b && a>c)//Here, in this if both condition are becomes true then execute the if part due to '&&' logical operator.
        {
            if(b>c)//here,in this program we used neasted 'if' (means 'if' has another 'if' inside it.)
            {
                printf("Ascending order  :%d, %d, %d\n",c,b,a);
                printf("Descending order :%d, %d, %d\n",a,b,c);
            }
            else
            {
                printf("Ascending order  :%d, %d, %d\n",b,c,a);
                printf("Descending order :%d, %d, %d\n",a,c,b);
            }
        }
        else if(b>a && b>c)
        {
            if(a>c)
            {
                printf("Ascending order  :%d, %d, %d\n",c,a,b);
                printf("Descending order :%d, %d, %d\n",b,a,c);
            }
            else
            {
                printf("Ascending order  :%d, %d, %d\n",a,c,b);
                printf("Descending order :%d, %d, %d\n",b,c,a);
            }
        }
        else if(c>a && c>b)
        {
            if(a>b)
            {
                printf("Ascending order  :%d, %d, %d\n",b,a,c);
                printf("Descending order :%d, %d, %d\n",c,a,b);
            }
            else
            {
                printf("Ascending order  :%d, %d, %d\n",a,b,c);
                printf("Descending order :%d, %d, %d\n",c,b,a);
            }
        }
    }

Output:






👉Click for more C Program series Questions.[Questions list]

Comments

Popular Posts