# WAP in C++ & Python to find the largest & smallest element in Array

Posted in  Vinay Khatri
Last updated on November 15, 2022

Here in this program, we will code to find the largest and smallest element from a 1D Array .

## C++ Program to find the largest and smallest elements from an Array

Here you can take the below-listed program If you want to find the largest and smallest elements from an array.

```#include<stdio.h>
#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int arr,num, elements, min, max;
cout<<"How many elements you want to enter?: ";
cin>>num;
cout<<"Enter the elements in the array\n";
for(int i=0; i<num;i++)
cin>>arr[i];
max=arr;
min=arr;
for(i=0; i<num; i++)
{
if(arr[i]>max)
max= arr[i];
if(arr[i]<min)
min= arr[i];
}
cout<<"The largest Element is: "<<max<<endl;
cout<<"The smallest Element is: "<<min<<endl;
getch();
}```

Output:

```How many elements you want to enter?: 5
Enter the elements in the array

3
1
4
5
23

The largest Element is: 23
The smallest Element is: 1```

### Python Program

```arr=[]
num = int(input("How many elements you want to enter?: "))
print("Enter the elements in the array")
for i in range(num):
element = int(input())
arr.append(element)
print("The largest Element is:",max(arr))
print("The smallest Element is:",min(arr))```

Output:

```How many elements you want to enter?: 7
Enter the elements in the array

20
234
2345
23
55
345
656

The largest Element is: 2345
The smallest Element is: 20```

## Conclusion

This is all about printing the find the largest & smallest element in Array by writing code in Python and C Programming Languages. If you think there is some other topic that you think we should write an article or prepare codebase to help you then list down that in the given comment section below. People are also reading: