Find the Largest of n Numbers Using the C Program

In the world of programming finding the largest element is a common task. In this article, we are going to write a C program to find the largest of n numbers.

Objective

The objective of this tutorial is to write a C program that accepts n numbers as input and finds the largest among them.

Algorithm for Finding the Largest Number

To write a C program that efficiently finds the largest number among n numbers, We will use a simple algorithm. The steps of the algorithm are given below-

  • Start the program.
  • Declare Variables – n for a total count of numbers, num to hold each input number, and largest to hold the largest of n numbers.
  • Start a loop to take n numbers as input.
  • Compare num with largest, if num>largest assign num to largest that is largest = num.
  • Display the largest number as the output.
  • End of thev program.

C Program for Finding the Largest Number

Let’s implement the above algorithm using the C program.

Output

C Program for Finding the Largest Number

The above C program asks the user to input a total number of counts after that proceeds to accept n numbers one by one, using a loop. It compares each input number with the largest and updates the largest if the new number is greater.

See Also

3 thoughts on “Find the Largest of n Numbers Using the C Program”

Leave a Comment