#include <stdio.h>
#include <conio.h>
void main()
{
int array[10];
int i, j, N, temp;
int findmax(int b[10], int k); /* function declaration */
void exchang(int b[10], int k);
clrscr();
printf(“Enter the value of N\n”);
scanf(“%d”,&N);
printf(“Enter the elements one by one\n”);
for(i=0; i<N ; i++)
{
scanf(“%d”,&array[i]);
}
printf(“Input array elements\n”);
for(i=0; i<N ; i++)
{
printf(“%d\n”,array[i]);
}
/* Selection sorting begins */
exchang(array,N);
printf(“Sorted array is…\n”);
for(i=0; i< N ; i++)
{
printf(“%d\n”,array[i]);
}
} /* End of main*/
/* function to find the maximum value */
int findmax(int b[10], int k)
{
int max=0,j;
for(j = 1; j <= k; j++)
{
if ( b[j] > b[max])
{
max = j;
}
}
return(max);
}
void exchang(int b[10],int k)
{
int temp, big, j;
for ( j=k-1; j>=1; j–)
{
big = findmax(b,j);
temp = b[big];
b[big] = b[j];
b[j] = temp;
}
return;
}
/*—————————–
Output
Enter the value of N
5
Enter the elements one by one
45
12
90
33
78
Input array elements
45
12
90
33
78
Sorted array is
12
33
45
78
90
———————————–*/
Not Satisfied ? Just search & get the result
Related posts:
- C program to sort N numbers in ascending order array with suitable headings
- C program to read in four integer numbers into an array and find the average of largest two of the given numbers without sorting the array. The program should output the given four numbers and the average with suitable headings.
- C program to read N integers (zero, +ve and -ve) into an array A and to a) Find the sum of negative numbers b) Find the sum of positive numbers and c) Find the average of all input numbers Output the various results computed with proper headings
- C program to accept N numbers sorted in ascending order and to search for a given number using binary search. Report success or failure in the form of suitable messages
- C program to read N names, store them in the form of an array and sort them in alphabetical order. Output the give names and the sorted names in two columns side by side with suitable heading
