1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include<stdio.h>
#include<conio.h>
void asce(int[],int);
void main()
{
int a[10],n,i;
printf("Enter total no of array to be inserted in array:- ");
scanf("%d",&n);
printf("Enter value to be inserted in array");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
asce(a,n);
printf("After arrranging in ascending order:- \n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
getche();
}
void asce(int a[10],int y)
{
int i,j,tmp;
for (i=0;i<y;i++)
{
for(j=0;j<y-1;j++)
{
if(a[j]>a[j+1])
{
tmp=a[j+1];
a[j+1]=a[j];
a[j]=tmp;
}
}
}
}
|
The main concept is the nested for loop. There are 100s ways to perform a program. The return type of called function is void as value is passed by reference.
0 comments:
Post a Comment