Cpp program to find largest elements of an Array
- Home
- Find elements
- Cpp program to find largest elements of an Array
- On
- By
- 0 Comment
- Categories: Find elements
Cpp program to find largest elements of an Array
Cpp program to find largest elements of an Array
In this tutorial, we will discuss the small concept of Cpp program to find the largest elements of an Array.
In this topic, we will learn how to find the largest elements of array elements in Cpp programming language
This program gets “n” number of elements and Enter the elements of the array as input from the user. then, this program finds and displays the largest elements from the array using for loops.
In this programs, we can see step by step procedure for completion of the program.
- array declaration
- Essential variable declaration
- Get input from the user for array length
- Get input from the user for array elements
- loop for largest value
- Display result on the screen
Find largest elements from integer Array
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { int arr[30];//array declaration int length,i, max; //essential variable declaration cout<<"Enter the length of the array: "; cin>>length;//get input from user for length for(i=0; i<length; i++){ cout<<"Enter element "<<i+1<<" :";//enter elements for array cin>>arr[i]; } max=arr[0]; for(i=0; i<length; i++){ if(max<arr[i]){ max=arr[i]; } } cout<<"\nlargest elements is:"<<max; getch(); return 0; }
When the above code is compiled and executed, it produces the following results
Enter the length of the array: 5 Enter element 1:87 Enter element 1:65 Enter element 1:78 Enter element 1:43 Enter element 1:56 largest element si: 87
Find largest elements from float Array
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { float array[100];//Array declaration int length,i; double max;//variable declaration cout << "Enter the length of the array: " << endl; cin>>length;//Takes input from user for length for(i=0; i<length; i++){ cout<<"Enter element "<<i+1<<" :";//enter elements for array cin>>array[i]; } max=array[0]; for(i=0; i<=length; i++){ if(max<array[i]){ max=array[i]; } } cout<<"\n Largest elements is: "<<max; getch(); return 0; }
When the above code is compiled and executed, it produces the following results
Enter the length of the array: 5 Enter element 1 :4.6 Enter element 1 :3.7 Enter element 1 :7.9 Enter element 1 :9.8 Enter element 1 :3.2 Largest elements is: 9.8
Similar post
largest number of three number in C
largest number of three number in C++
largest number of three number in Python
largest number of three number in C using function
largest number of three number in C++ using function
largest number of three number in Python using function
largest number of three number in Java using method
Suggested for you
Single dimension Array in C++ language
Data type in C++ programming language
Two dimension array in C++ language
Three dimension array in C++ language
If statements in Java language
Single dimension array in Java language
Two dimension array in Java language
Three dimension array in Java language
Operator in C language with example
Single dimension array in C language