Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- void main()
- {
- int i,j,temp,no,type,a[10];
- printf("Enter count of no. = ");
- scanf("%d",&no);
- printf("For Ascending Order Press 1, Press 2 for Descending Order = ");
- scanf("%d",&type);
- printf("Enter no. = ");
- for(i=0;i<no;i++)
- scanf("%d",&a[i]);
- for(i=0;i<no;i++)
- {
- for(j=0;j<(no-i);j++)
- {
- if(type!=2)
- {
- if(a[j]>a[j+1])
- {
- temp=a[j];
- a[j]=a[j+1];
- a[j+1]=temp;
- }
- }
- else
- {
- if(a[j]<a[j+1])
- {
- temp=a[j];
- a[j]=a[j+1];
- a[j+1]=temp;
- }
- }
- }
- }
- printf("Sorted No. = ");
- for(i=0;i<no;i++)
- printf("%d ",a[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement