how to get the largest number in a c++ array
C++
#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;
}
Also in C++:
- Title
- how to print a string to console in c++
- Category
- C++
- Title
- can you use rand to read in from an external file inc++
- Category
- C++
- Title
- binary search in set c++
- Category
- C++
- Title
- c++ find object in vector by attribute
- Category
- C++
- Title
- Application of c++ in youtube program
- Category
- C++
- Title
- preorder traversal c++
- Category
- C++
- Title
- c++ multiple inheritance diamond problem
- Category
- C++
- Title
- printf c++
- Category
- C++
- Title
- Find the minimum difference between pairs in a simple path of tree C++
- Category
- C++
- Title
- c++ string to vector int
- Category
- C++
- Title
- cut by delimiter c++
- Category
- C++
- Title
- split string at index c++
- Category
- C++
- Title
- how to sort an array c++
- Category
- C++
- Title
- checking an int in c++
- Category
- C++
- Title
- mingw32/bin/ld.exe: C:\Users\mfrom\AppData\Local\Temp\ccSKcRks.o:PizzaPi.cpp:(.text$_ZN5PizzaC2Ev[__ZN5PizzaC2Ev]+0xa): undefined reference to `vtable for Pizza' collect2.exe: error: ld returned 1 exit status
- Category
- C++
- Title
- first prime numbers less than
- Category
- C++
- Title
- floor() in c++
- Category
- C++
- Title
- create a 2d array c++
- Category
- C++
- Title
- how to convert int to string c++
- Category
- C++
- Title
- never gonna give you up
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- c++ append to list
- Category
- C++
- Title
- c++ map find
- Category
- C++
- Title
- how to make a 2d vector in c++
- Category
- C++
- Title
- min and max heap in cpp
- Category
- C++
- Title
- C++ and endl
- Category
- C++
- Title
- input a string in c++
- Category
- C++
- Title
- quick sort predefined function in c++
- Category
- C++
- Title
- create copy of range of string c++
- Category
- C++
- Title
- command line options in c++
- Category
- C++
- Title
- caesar cipher program in c++
- Category
- C++
- Title
- cout console
- Category
- C++
- Title
- c++ program to input and print text using Dynamic Memory Allocation.loop
- Category
- C++
- Title
- popualte an array c++
- Category
- C++
- Title
- how to find the mode of a vector c++
- Category
- C++
- Title
- c++ typedef
- Category
- C++
- Title
- c++ client service ros
- Category
- C++
- Title
- nearest integer rounding in c++
- Category
- C++
- Title
- print type cpp
- Category
- C++
- Title
- c++ menu selection with arrow keys
- Category
- C++
- Title
- primeros numeors primos menores que
- Category
- C++
- Title
- min heap declaration in c++ stl
- Category
- C++
- Title
- Read multiple files(.txt) c++
- Category
- C++
- Title
- c++ switch case statement
- Category
- C++
- Title
- c++ class member initialization
- Category
- C++
- Title
- how to get os name in c++
- Category
- C++
- Title
- C++ remove element from set
- Category
- C++
- Title
- c++ convert int to cstring
- Category
- C++
- Title
- function template
- Category
- C++
- Title
- cout value c++
- Category
- C++
- Title
- how to ensure the user inouts a int and not anything else c++
- Category
- C++
- Title
- RLE Encoding/Compression c++
- Category
- C++
- Title
- shortest path with bfs in c++
- Category
- C++
- Title
- c++ formatting
- Category
- C++
- Title
- zeros of array c++
- Category
- C++
- Title
- COnvert string to char * C++
- Category
- C++
- Title
- how to find the size of a character array in c++
- Category
- C++
- Title
- c++ files
- Category
- C++
- Title
- c++ clamp
- Category
- C++
- Title
- object slicing in c++
- Category
- C++
- Title
- restting a queue stl
- Category
- C++
- Title
- c++ string
- Category
- C++
- Title
- c++ vector add element
- Category
- C++
- Title
- int max in c++
- Category
- C++
- Title
- find in vector in c++
- Category
- C++
- Title
- how to round to nearest whole number unity
- Category
- C++
- Title
- Newton's sqrt in c++
- Category
- C++
- Title
- inserting an element in an set c++
- Category
- C++
- Title
- basic ex of maps in c++
- Category
- C++
- Title
- can you use a return to print a string when referencing an integer c++
- Category
- C++
- Title
- how use global variables instead of local in c++
- Category
- C++
- Title
- min in vector c++
- Category
- C++
- Title
- ios_base::sync_with_stdio(false);cin.tie(NULL);
- Category
- C++
- Title
- sort a pair using c++ stl
- Category
- C++
- Title
- c++ iterate through constant list
- Category
- C++
- Title
- c++ vector iterator
- Category
- C++
- Title
- get data from terminal c++
- Category
- C++
- Title
- c++ try
- Category
- C++
- Title
- c++ unittest in ros
- Category
- C++
- Title
- double to string c++
- Category
- C++
- Title
- substr in c++
- Category
- C++
- Title
- c++ char to int
- Category
- C++
- Title
- how to convert qt string to string
- Category
- C++
- Title
- differentialble programming
- Category
- C++
- Title
- switch c++
- Category
- C++
- Title
- programa para saber si un numero es primo
- Category
- C++
- Title
- c++ main function
- Category
- C++
- Title
- cloud hosting
- Category
- C++
- Title
- self in c++
- Category
- C++
- Title
- c++ read file line by line
- Category
- C++
- Title
- c++ compare char
- Category
- C++
- Title
- substr c++
- Category
- C++
- Title
- c++ cli convert string to string^
- Category
- C++
- Title
- remove value from vector c++
- Category
- C++
- Title
- c++ parse int
- Category
- C++
- Title
- how to use a new node c++
- Category
- C++
- Title
- nginx linux
- Category
- C++
- Title
- retu7rn this c++
- Category
- C++
- Title
- c++ overload operator
- Category
- C++
- Title
- how to have a queue as a parameter in c++
- Category
- C++