C program to find largest number of a list of numbers entered through keyboard

Here is the C program to find the largest number of a list of numbers entered through the keyboard:

				
					#include <stdio.h>

int main() {
  int n, i, max = 0, number;

  printf("Enter the number of numbers: ");
  scanf("%d", & n);

  for (i = 0; i < n; i++) {
    printf("Enter number %d: ", i + 1);
    scanf("%d", & number);

    if (number > max) {
      max = number;
    }
  }

  printf("The largest number is %d\n", max);

  return 0;
}
				
			
Output
C program to find largest number from the list

This program works by first getting the number of numbers from the user. Then, it uses a loop to get each number from the user. In each iteration of the loop, it checks if the number is greater than the current largest number. If it is, then it updates the largest number to the new number. Finally, it prints the largest number.

Here is a breakdown of how the program works:

  • The printf() function is used to print the prompt “Enter the number of numbers: “.
  • The scanf() function is used to read the number of numbers from the user.
  • The for loop is used to get each number from the user. In each iteration of the loop, the number is read from the user using the scanf() function.
  • The if statement is used to check if the number is greater than the current largest number. If it is, then the value of the number is assigned to the variable max.
  • The printf() function is used to print the largest number.
  • The return 0 statement is used to indicate that the program has completed successfully.