Advertisement
Guest User

Untitled

a guest
Jul 7th, 2012
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. #include<stdio.h>
  2. void main()
  3. {
  4.     int i,j,temp,no,type,a[10];
  5.     printf("Enter count of no. = ");
  6.     scanf("%d",&no);
  7.     printf("For Ascending Order Press 1, Press 2 for Descending Order = ");
  8.     scanf("%d",&type);
  9.     printf("Enter no. = ");
  10.     for(i=0;i<no;i++)
  11.         scanf("%d",&a[i]);
  12.     for(i=0;i<no;i++)
  13.     {
  14.         for(j=0;j<(no-i);j++)
  15.         {
  16.              if(type!=2)
  17.              {
  18.                 if(a[j]>a[j+1])
  19.                 {
  20.                     temp=a[j];
  21.                     a[j]=a[j+1];
  22.                     a[j+1]=temp;
  23.  
  24.                 }
  25.              }
  26.              else
  27.              {
  28.                 if(a[j]<a[j+1])
  29.                 {
  30.                     temp=a[j];
  31.                     a[j]=a[j+1];
  32.                     a[j+1]=temp;
  33.  
  34.                 }
  35.              }
  36.         }
  37.     }
  38.     printf("Sorted No. = ");
  39.     for(i=0;i<no;i++)
  40.         printf("%d  ",a[i]);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement