Non-Recursive C Program:
Aim:
To sort a array of Elements in Ascending order. ( Bubble Sort )
Program:
#include<stdio.h>
#include<conio.h>
void main ( )
{
int A[25],i,j,m,temp;
printf("Enter the size of array:");
scanf("%d",&m);
printf("\nEnter the Elements:");
for( i=0;i<m;i++)
{
scanf("%d",&A[i]);
}
Printf("The Entered Elements: \n ");
for( i=0;i<m;i++)
{
printf("%d\t",A[i]);
}
for( i=0;i<m;i++)
{
for( j=0;j<m-i-1;j++)
{
if( A[j] > A[j+1] )
{
temp = A[j+1];
A[j+1] = A[j];
A[j] = temp;
}
}
}
printf("\nArray Elements in Ascending order:");
for( i=0;i<m;i++)
{
printf("%3d",A[i]);
}
}
Output:
Enter the size of array: 6
Enter the Elements:
82
32
4
17
45
11
The Entered Elements:
82 32 4 17 45 11
Array Elements in Ascending order:
4 11 17 32 45 82
No comments:
Post a Comment