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.
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
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
Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…
Python program to calculate the sum of odd and even numbers in a list In…
Python code to Calculate sum of odd and even in a list In this tutorial,…
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…