Home / Programs / C Program to Find Largest Element in Array in C Programming
Programming Example

C Program to Find Largest Element in Array in C Programming

👁 1,125 Views
💻 Practical Program
📘 Step by Step Learning
C Program to Find Largest Element in Array in C Programming

Program Code

#include<stdio.h>

int main() {
   int a[30], i, num, largest;

   printf("\nEnter no of elements :");
   scanf("%d", &num);

   //Read n elements in an array
   for (i = 0; i < num; i++)
      scanf("%d", &a[i]);

   //Consider first element as largest
   largest = a[0];

   for (i = 0; i < num; i++) {
      if (a[i] > largest) {
         largest = a[i];
      }
   }

   // Print out the Result
   printf("\nLargest Element : %d", largest);

   return (0);
}

Output

Enter no of elements : 5
11 55 33 77 22
Largest Element : 77

Explanation

none

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.