c program for sorting of arrays in descending order
How to write a program for sort numbers in c code descending order
#include<stdio.h>
void sort(int a[]);
void main()
{
int a[10],i;
clrscr();
printf("\nEnter 10 elements in array:");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
sort(a);
}
void sort(int a[10])
{
int temp,i,j;
printf("\nArray in Ascending Order:");
for(i=0;i<10;i++)
for(j=i+1;j<10;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
for(i=0;i<10;i++)
printf("%d ",a[i]);
printf("\n\nArray in Descending Order:");
for(i=9;i>=0;i--)
printf("%d ",a[i]);
}
array sort examples
How to write a program for sort numbers in c code descending order
#include<stdio.h>
void sort(int a[]);
void main()
{
int a[10],i;
clrscr();
printf("\nEnter 10 elements in array:");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
sort(a);
}
void sort(int a[10])
{
int temp,i,j;
printf("\nArray in Ascending Order:");
for(i=0;i<10;i++)
for(j=i+1;j<10;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
for(i=0;i<10;i++)
printf("%d ",a[i]);
printf("\n\nArray in Descending Order:");
for(i=9;i>=0;i--)
printf("%d ",a[i]);
}
array sort examples
0 comments: