Saturday, April 9, 2016

Descending Numbers in C

Here is a sample program that I wrote a very long time a ago in C language that will ask a series of numbers and then it will sort the given numbers into descending order.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Program Listing

#include <stdio.h>
#include <conio.h>

int main()
{
     int arr[100],i,j,element,no,temp;
     clrscr();
     printf("\nEnter the no of Elements: ");
     scanf("%d", &no);
     for(i=0;i<no;i++){
          printf("\n Enter Element %d: ", i+1);
          scanf("%d",&arr[i]);
     }
     for(i=0;i<no;i++){
          for(j=i;j<no;j++){
               if(arr[i] < arr[j]){
               temp=arr[i];
               arr[i]=arr[j];
               arr[j]=temp;
               }
           }
     }
     printf("\nSorted array:");
     for(i=0;i<no;i++){
          printf("\t%d",arr[i]);
     }
     getch();
}





No comments:

Post a Comment