
C program to find the largest element in an array
Algorithm
Input: Input size of the array and elements of the array
output: Displays the largest element in an array
- Start
- Input the size of array say n and enter the elements of the array a[n]
- large = a[0]
- i = 0
- while ( i<n )
5.1 if large < a[ i ]
5.1.1 large = a [ i ]
5.2 i++ - print " The largest elements in the array is " large
- stop
C Program
#include <stdio.h>
int main()
{
int n,large;
printf("Enter the size of array: ");
scanf("%d", &n);
int a[n];
printf("Enter the elements one by one\n");
for (int i = 0; i<n; i++) {
scanf("%d", &a[i]);
}
large = a [0];
for (int i = 0; i<n; i++) {
if ( large < a [ i ]) {
large = a [ i ];
} }
printf("The largest element in the array is %d \n", large);
}
Note: This Program was created using visual studio code. The Program file can be downloaded by clicking here
Flowchart

Note: This Flowchart was created using a program called Raptor. The flowchart file can be downloaded by clicking here
Comments