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 descending order.


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

#include<stdio.h>
#include<conio.h>
  void main()
    {
      int temp,i,n,j,a[30];
      clrscr();
      printf("How many number you want enter in an array.:-");
      scanf("%d",&n);
      printf("Enter %d nos.:-",n);
      for(i=0;i<n;i++)  
    scanf("%d",&a[i]);
   for(i=0;i<n;i++)
     {
      for(j=i+1;j<n;j++)
        {
         if(a[i]<a[j])
           {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
         }
     }
  }   
 printf("Sort of arranged in descending order=");
 for(i=0;i<n;i++)
  printf("%4d",a[i]);
  getch();
 }

Output:-

Related programs:
  1.    Write a program in C to sort array elements in ascending  order.
  2.    Write a program in C to check that a number entered by the user is Armstrong number.
  3.    Write a program to print 1 to 100 numbers using while loop.
  4.     Write a program in C to find greatest prime number less than a given positive number. 

Post a Comment

0 Comments