Wednesday, 5 December 2012

CPL PROGRAM 13 CODING

            SORTING THE ARRAY ELEMENTS
                                                        
CODING:                                                               
                                                                                                          
#include<stdio.h>
#include<conio.h>
void main()
{
  clrscr();
  int a[10],i,n,t,j;
  printf("Enter the limit");
  scanf("%d",&n);
  printf("Enter the array values");
  for(i=0;i<n;i++)
  {
   scanf("%d",&a[i]);
  }
  for(i=0;i<n-1;i++)
  {
   for(j=i+1;j<n;j++)
   {
    if(a[i]>a[j])
    {
     t=a[i];
     a[i]=a[j];
     a[j]=t;
    }
   }
  }
  printf("sorted elements are");
  for(i=0;i<n;i++)
  {
   printf("%d",a[i]);
  }
  getch();
}

No comments:

Post a Comment