#include<stdio.h>
#include<conio.h>
int main()
{
int ar[100],j,n,i,tmp;
printf(" Enter the size of the array \t");
scanf("%d",&n);
printf("Now enter the elements in the array \t");
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
}
printf("\n Array is - ");
for(i=0;i<n;i++)
{
printf("\t %d",ar[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(ar[j]>ar[j+1])
{
tmp=ar[j];
ar[j]=ar[j+1];
ar[j+1]=tmp;
}
}
}
printf("\n\n Array in the ascending order is - \n");
for(i=0;i<n;i++)
{
printf("\t %d",ar[i]);
}
getch();
return 0
}
; Enter the size of the array 4
Now enter the elements in the array 45
65
23
32
Array is - 45 65 23 32
Array in the ascending order is -
0 23 32 45
#include<conio.h>
int main()
{
int ar[100],j,n,i,tmp;
printf(" Enter the size of the array \t");
scanf("%d",&n);
printf("Now enter the elements in the array \t");
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
}
printf("\n Array is - ");
for(i=0;i<n;i++)
{
printf("\t %d",ar[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(ar[j]>ar[j+1])
{
tmp=ar[j];
ar[j]=ar[j+1];
ar[j+1]=tmp;
}
}
}
printf("\n\n Array in the ascending order is - \n");
for(i=0;i<n;i++)
{
printf("\t %d",ar[i]);
}
getch();
return 0
}
; Enter the size of the array 4
Now enter the elements in the array 45
65
23
32
Array is - 45 65 23 32
Array in the ascending order is -
0 23 32 45
No comments:
Post a Comment
Note: only a member of this blog may post a comment.