Showing posts with label largest of list. Show all posts
Showing posts with label largest of list. Show all posts

C / C++ Program to find the Largest number from the array of integers

Leave a Comment
/* The following C / C++ Program will find the largest number among numbers in the integer array thus entered by the user. We have used while loop to read & write the array*/

Code:-
#include<iostream>
#include<conio.h>
using namespace std;
void main ()
{
int a[100];
int max,b=0,c,n;
cout<<"\nEnter the total number of elements in array(<100):";
cin>>n;
while (b<n)
{
cout<<"Enter the element number "<<b<<" : ";
cin>>c;
a[b]=c;
b=b+1;
}
b=0;
max=a[b];
//assuming that the 1st element is the maximum
while (b<n)
{
if (a[b]>=max)
//if anything else is found to be more larger than the current maximum
{
max=a[b];
}
b=b+1;
}
cout<<"\nLargest number is : "<<max;
getche();
}



Output:
C / C++ Program to find the Largest number from the array of integers
C / C++ Program to find the Largest number from the array of integers

Read More...

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
 
Read More...