adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Write a program in C to sort array elements in ascending order.




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:

Post a Comment

0 Comments