021. Write a program to accept three numbers from user and print them in ascending and decending order in C language

#include<stdio.h>
#include<conio.h> 
main()
{
 int a,b,c;
 clrscr();
 printf("Enter numbers...");
 scanf("%d%d%d",&a,&b,&c);
 if((a>=b)&&(a>=c))
 {
    if(b>=c)
    {
     printf("\n Descending order : %d %d %d",a,b,c);
     printf("\n Ascending order : %d %d %d",c,b,a);
    }
    else
    {
     printf("\n Descending order : %d %d %d",a,c,b);
     printf("\n Ascending order : %d %d %d",b,c,a);
    }
 }
 else if((b>=a)&&(b>=c))
 {
    if(a>=c)
    {
     printf("\n Descending order : %d %d %d",b,a,c);
     printf("\n Ascending order : %d %d %d",c,a,b);
    }
    else
    {
     printf("\n Descending order : %d %d %d",b,c,a);
     printf("\n Ascending order : %d %d %d",a,c,b);
    }
 }
 else if((c>=a)&&(c>=b))
 {
  if(a>=b)
  {
     printf(" Descending order : %d %d %d",c,a,b);
     printf(" Ascending order : %d %d %d",b,a,c);
  }
  else
  {
     printf(" Descending order : %d %d %d",c,b,a);
     printf(" Ascending order : %d %d %d",a,b,c);
  }
}
 getch();
}

14 thoughts on “021. Write a program to accept three numbers from user and print them in ascending and decending order in C language

    1. #include
      #include
      void main()
      { clrscr();
      int a=1,s=0,s1=0,f=0;
      cout<>a;
      for(int i=2;i<a/2;i++)
      { if(a%i==0)
      { f=1;
      break;
      }
      }
      if(f==1)
      cout<<":::::::::::::::::::::::::::::Not Prime:::::::::::::::::::::::::::::::";
      if(f==0)
      cout<<"::::::::::::::::::::::::::::::::::Prime:::::::::::::::::::::::::::::::";
      getch();
      }

  1. In the program of printing ascending and descending of 3 numbers…. you have made a mistake in all the printf statements i.e.,you are printing ascending order but you named it as descending…… ascending means printing numbers from small to big whereas u r printing the numbers big to small

  2. i’ve made the exact program in the turbo c compiler and its working perfectly fine….there is no problem in the program.. u must have interchanged the values of a,b,c in the scanf statement..

Leave a Reply

Your email address will not be published. Required fields are marked *