C++ program to find largest number of an array
0
Consider below is the input array, where you want to find the largest number of an array.
1. C++ program to find the largest number of an array
Run here
In the above program,
- we have initialized the array with input.
- Using for loop we are traversing array from second element till the last element of the array
- Then we are comparing every element present in the array with the first element and then assigning the larger value to
arr[0]
variable - Printing the
arr[0]
which gives the largest value
Results
2. C++ program to find the largest number of an array with user provided input
Try yourself here by providing input in the stdin section
In the above program,
- We are taking array size and array elements from user.
- Using for loop we are traversing array from second element till the last element of the array
- Then we are comparing every element present in the array with the first element and then assigning the larger value to
arr[0]
variable - Printing the
arr[0]
which gives the largest value