#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],n,i,j,t;
printf("Sorting\n");
printf("------\n");
printf("Enter the limit of number\n");
scanf("%d",&n);
printf("Enter the elements one by one\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Before Sorting\n");
printf("------------\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("After Sorting\n");
printf("-----------\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
}
-----------
OUTPUT:
-----------
[smca13@SRNM smca13]$ cc sortdbase.c
[smca13@SRNM smca13]$ ./a.out sortdbase.c
Sorting
-------
Enter the limit of number
5
Enter the elements one by one
20
53
12
86
48
Before Sorting
---------------
20
53
12
86
48
After Sorting
-------------
12
20
48
53
86
#include<conio.h>
void main()
{
int a[20],n,i,j,t;
printf("Sorting\n");
printf("------\n");
printf("Enter the limit of number\n");
scanf("%d",&n);
printf("Enter the elements one by one\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Before Sorting\n");
printf("------------\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("After Sorting\n");
printf("-----------\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
}
-----------
OUTPUT:
-----------
[smca13@SRNM smca13]$ cc sortdbase.c
[smca13@SRNM smca13]$ ./a.out sortdbase.c
Sorting
-------
Enter the limit of number
5
Enter the elements one by one
20
53
12
86
48
Before Sorting
---------------
20
53
12
86
48
After Sorting
-------------
12
20
48
53
86
0 comments:
Post a Comment