CPP Program find the largest number in the array
In this program, you will learn about the find the largest number in the array in the cpp programming language.
If you have knowledge about the c++ array, the c++ loop help in understanding the program.
Code:
#include <iostream>
using namespace std;
int main()
{
int i, n;
float arr[10]={1,2,3,4,5,6,7,8,9,10};
// Loop to store largest number to arr[0]
for(i = 1;i < n; ++i)
{
// Change < to > if you want to find the smallest element
if(arr[0] < arr[i])
arr[0] = arr[i];
}
cout << "Largest element = " << arr[0]<<endl;
return 0;
}
Output:
Largest element = 10
Comments
Post a Comment