"how to get the largest number in a c++ array" Code Answer's
You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "how to get the largest number in a c++ array" answered properly. Developers are finding an appropriate answer about how to get the largest number in a c++ array related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like how to get the largest number in a c++ array. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on how to get the largest number in a c++ array.
how to get the largest number in a c++ array
#include <iostream>
using namespace std;
int main(){
//n is the number of elements in the array
int n, largest;
int num[50];
cout<<"Enter number of elements you want to enter: ";
cin>>n;
/* Loop runs from o to n, in such a way that first
* element entered by user is stored in num[0], second
* in num[1] and so on.
*/
for(int i = 0; i < n; i++) {
cout<<"Enter Element "<<(i+1)<< ": ";
cin>>num[i];
}
// Storing first array element in "largest" variable
largest = num[0];
for(int i = 1;i < n; i++) {
/* We are comparing largest variable with every element
* of array. If there is an element which is greater than
* largest variable value then we are copying that variable
* to largest, this way we have the largest element copied
* to the variable named "largest" at the end of the loop
*
*/
if(largest < num[i])
largest = num[i];
}
cout<<"Largest element in array is: "<<largest;
return 0;
}
Source: beginnersbook.com
All those coders who are working on the C++ based application and are stuck on how to get the largest number in a c++ array can get a collection of related answers to their query. Programmers need to enter their query on how to get the largest number in a c++ array related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about how to get the largest number in a c++ array for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of how to get the largest number in a c++ array while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "how to get the largest number in a c++ array". Visit this developer's friendly online web community, CodeProZone, and get your queries like how to get the largest number in a c++ array resolved professionally and stay updated to the latest C++ updates.