C program to Find the largest of the numbers entered in an array, using the technique of array sorting

Leave a Comment
/* In the given program written in C, we have used the technique of array sorting instead of sequential search for finding the greatest of the numbers present in the array. The array is first sorted in the descending order, thus the greatest number in the list will be the 1st element of the array i.e., of whose the index number is '0', you can also choose to sort the array in ascending order then the largest number be in the end element of the array*/


#include<stdio.h>
#include<conio.h>
int main()
{
int num[100], a, b, help, n;
printf("how many numbers you want\n");
scanf("%d",&n);
for(a=0;a<n;a++)
{
printf("enter element %d\n",a+1);
scanf("%d",&num[a]);
}
for(a=0;a<n;a++)
{
for(b=a+1;b<n;b++)
{
if (num[b]>num[a])
{
help=num[b];
num[b]=num[a];
num[a]=help;
}
}
}
printf("\nthe largest number is %d",num[0] );
getch();
}
Screenshot:
C program to Find the largest of the numbers entered in an array, using the technique of array sorting
 

0 comments: