C program to find the largest number in array.

Posted by Mangesh on March 19, 2018

/* Program in c to find largest number in array. */

Description :

We have a array of integers, and we need to find the largest number in the array.

Logic :

We should store the first element in largest variable. Then we must compare second element with largest and store larger element in the largest variable, Then we must compare third element with largest and store larger element in the largest variable, and so on till nth variable. At the end we with get largest element.

Program :

#include<stdio.h>
#include<conio.h>
void main()
{
  int arr[20];
  int i,n,largest;
  printf("\n\nEnter total number of elemnt in array : ");
  scanf("%d",&n);
  for(i=0;i<n;i++)
  { 
    printf("Enter %d element : ",i+1);
    scanf("%d",&arr[i]);
  }
  largest = arr[0];
  for(i=1;i<n;i++)
  {
    if(arr[i] > largest)
      largest = arr[i];
  }
  printf("Largest number is %d",largest);
  getch();
}

Output :

C program to find largest number in array. Test in Turbo C 3.2

Written with from Mangesh.

Related Post
1 C program to reverse element in array.
2 C program to find the smallest number in array.
3 C program to find the largest number in array.
4 C program for addition of 2D matrix.
5 C program to calculate sum of all elements in array.
Latest Post
1 shubhanshu
2 test
3 C program for Breadth First Search.
4 C program for Depth First Search(DFS).
5 C for circular queue using linked list.