codescracker


c++

C++ Program to Find Largest Element in Array



« Previous Program Next Program »


Find Largest Element in Array in C++

To find the largest element in an array in C++ programming, you have to ask to the user to enter the array size, again ask to enter the array elements. Now start finding for the largest element in the array to display the largest element of the array on the output screen as shown here in the following program.

C++ Programming to Find Largest Element in Array

Following C++ program ask to the user to enter the array size and then array element to find the largest number present in the array, then display the result on the screen:

/* C++ Program - Find Largest Element in Array */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	int large, arr[50], size, i;
	cout<<"Enter Array Size (max 50) : ";
	cin>>size;
	cout<<"Enter array elements : ";
	for(i=0; i<size; i++)
	{
		cin>>arr[i];
	}
	cout<<"Searching for largest number ...\n\n";
	large=arr[0];
	for(i=0; i<size; i++)
	{
		if(large<arr[i])
		{
			large=arr[i];
		}
	}
	cout<<"Largest Number = "<<large;
	getch();
}

When the above C++ program is compile and executed, it will produce the following result:

C++ program find largest element in array

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test