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

Operator in C++ language

Single dimension Array in C++ language

For loop in C++ language

If statements in C++

Data type in C++ programming language

Two dimension array in C++ language

Three dimension array in C++ language

 

Operator in Java language

For loop in Java language

If statements in Java language

Data type 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

For loop in C language 

If statements in C language

Data type in C language

Single dimension array in C language

Two dimension array in C language

Three dimension array in C language

Program to find largest number among three numbers in Java
Java code to find largest elements of an Array
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

Explanation of one dimensional array (Data structure)

Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…

1 day ago

Python program to calculate the sum of odd and even numbers in a list

Python program to calculate the sum of odd and even numbers in a list In…

4 days ago

Python code to Calculate sum of odd and even in a list

Python code to Calculate sum of odd and even in a list In this tutorial,…

1 week ago

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 weeks ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

1 month ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

2 months ago