Find largest element of an array in C++
Find largest element of an array in C++
#include <iostream>
using namespace std;
int main() {
int i, n;
float arr[100];
cout << "Enter total number of elements(1 to 100): ";
cin >> n;
cout << endl;
// Store number entered by the user
for(i = 0; i < n; ++i) {
cout << "Enter Number " << i + 1 << " : ";
cin >> arr[i];
}
// 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 << endl << "Largest element = " << arr[0];
return 0;
}
Topics Covered :
- largest element
- find the biggest element in array
- program to find largest element in array
- c++ program to find largest element of an array
- lagrest element in array
- array
- computer science
- program
Thanks for reading this blog. Hope you get satisfied with the blog and definitely this blog must have valued your time and effort of reading.
Take a time to connect our other digital creations such as Instagram , Facebook and Youtube.
Β Social MediaΒ LinksΒ ofΒ Tech DCodeΒ :
Β YouTube :Β https://www.youtube.com/channel/UCjJnEdeugftBwQ3yMuD4B_A
Β Instagram :Β https://www.instagram.com/thetechdcode/
Β Facebook Page :Β https://www.facebook.com/thetechdcode
Β Twitter :Β https://twitter.com/thetechdcode
Β Telegram Channel :Β https://t.me/thetechdcode
Β Tech DCode Linktree :Β https://linktr.ee/thetechdcode
Β My Personal Handles :Β https://linktr.ee/virtualshivamin
Β Social Media LinksΒ ofΒ SHIVAM SINGHΒ (OWNER) :
Β Instagram :Β https://www.instagram.com/virtualshivamin/
Β Facebook Page :Β https://www.facebook.com/virtualshivamin/
Β Twitter :Β https://twitter.com/virtualshivamin/
Β Personal Linktree :Β https://linktr.ee/virtualshivaminΒ