c program to sort element of one dimensional array in ascending or descending order
c program to sort element of one dimensional array in ascending or descending order
Write a program to sort element of one dimensional array in ascending or descending order
Ascending
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,n,temp,a[1000];
printf("Enter the number of elements in the array:");
scanf("%d",&n);
for(i=0; i<n; i++){
printf("Enter the %d elements of array:",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("The sorted list in ascending order is:");
for(i=0; i<n; i++)
printf("%d\n",a[i]);
getch();
return 0;
}
Descending
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,n,temp,a[1000];
printf("Enter the number of elements in the array:");
scanf("%d",&n);
for(i=0; i<n; i++){
printf("Enter the %d elements of array:",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("The sorted list in descending order is:");
for(i=0; i<n; i++)
printf("%d\n",a[i]);
getch();
return 0;
}
You can Browse related article below for more information and program code related to recursive function call
Does above is helpful , Post you views in comment
198250A452
ReplyDeleteTakipçi Satın Al
Oyun Siteleri
SEO Ajansı
7E17BBD9
ReplyDeleteÜrgüp
Kundu
Karatay
Çayyolu
Artuklu
Menderes
Buharkent
Balçova
Bergama
8E5F2CA7
ReplyDeleteİlkadım
Çarşamba
Milas
Erciş
Kozan
Siverek
Ceyhan
Talas
Menderes