Write a program in C to sort array elements in ascending order.
#include<stdio.h> #include<conio.h> void main() { int temp,i,j,n,arr[30]; clrscr(); printf("Enter a no.:-"); scanf("%d",&n); printf("Enter %d nos.:-",n); for(i=0;i<n;i++) scanf("%d",&arr[i]); for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(arr[i]>arr[j]) { temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } } printf("Sort of arrary in ascending order="); for(i=0;i<n;i++) printf("%d ",arr[i]); getch(); }
Output:
Programs:
- Write a program in C to sort array elements in descending order.
- Write a program in C to check that a number entered by the user is Armstrong number.
- Write a program to print 1 to 100 numbers using while loop.
- Write a program in C to find greatest prime number less than a given positive number.
0 Comments