Program :
#include
#include
#define MAX 100 // maximum no of elements of array
int sortArray(int);
int array[MAX];
int main()
{
int i,size;
printf("\n>>>> PROGRAM TO SORT ARRAY USING FUNCTION <<<<\n\n");
printf("\n Enter the size of array: ");
scanf("%d",&size);
printf("\n Enter the %d elements of array: \n",size);
for(i=0;i
{
printf("\n array[%d]=",i);
scanf("%d", &array[i]);
}
sortArray(size); //calling sortArray() function
printf("\n The Sorted elements of array are:");
for(i=0;i
{
printf(" %d",array[i]);
}
getch();
return 0;
}
sortArray(n) // function for sorting array elements
{
int temp=0,i,j; // temp var is temporary variable used for swapping
for(i=0;i
{
for(j=i+1;j
{
if(array[i]>array[j])
{
temp=array[i]; //swapping for the array to be sorted
array[i]= array[j];
array[j]=temp;
}
}
}
}
Output :
#include
#include
#define MAX 100 // maximum no of elements of array
int sortArray(int);
int array[MAX];
int main()
{
int i,size;
printf("\n>>>> PROGRAM TO SORT ARRAY USING FUNCTION <<<<\n\n");
printf("\n Enter the size of array: ");
scanf("%d",&size);
printf("\n Enter the %d elements of array: \n",size);
for(i=0;i
{
printf("\n array[%d]=",i);
scanf("%d", &array[i]);
}
sortArray(size); //calling sortArray() function
printf("\n The Sorted elements of array are:");
for(i=0;i
{
printf(" %d",array[i]);
}
getch();
return 0;
}
sortArray(n) // function for sorting array elements
{
int temp=0,i,j; // temp var is temporary variable used for swapping
for(i=0;i
{
for(j=i+1;j
{
if(array[i]>array[j])
{
temp=array[i]; //swapping for the array to be sorted
array[i]= array[j];
array[j]=temp;
}
}
}
}
No comments:
Post a Comment