Menu
×
Tutorials Ms Word Tutorial Ms Excel Tutorial Ms PowerPoint Tutorial C Language Tutorial C++ Tutorial C Sharp Tutorial Visual Basic Tutorial HTML Tutorial CSS Tutorial JavaScript Tutorial WordPress Tutorial
     ❯   

ADVERTISEMENT

Find Largest of Three Numbers

This code takes three numbers as input and finds and displays the largest number among them. It demonstrates the use of conditional statements in C for decision-making based on user input.

#include<stdio.h>
main()
{
  int num1,num2,num3;
  printf("Enter a number 1\n");
  scanf("%d",&num1);
  printf("Enter a number 2\n");
  scanf("%d",&num2);
  printf("Enter a number 3\n");
  scanf("%d",&num3);
  if((num1>num2) && (num1>num3))
  {
     printf("%d is bigger\n",num1);
  }
  else if((num2>num1) && (num2>num3))
  {
    printf("%d is bigger\n",num2);
  }
  else
  {
    printf("%d is bigger\n",num3);
  }
}
C Programming Examples
OUTPUT
Enter a number 1
6
Enter a number 2
8
Enter a number 3
4
8 is bigger
C Programming Examples

Explanation:

This is a simple C program that takes three numbers as input and determines the largest among them. Here’s a step-by-step explanation of the code:

Header File:

  • The program includes the standard C library header <stdio.h>. This header is required for input and output operations.

Main Function:

  • The main function is the entry point of the program, where the execution begins.

Variable Declaration:

  • Three integer variables num1, num2, and num3 are declared to store the input numbers.

Input:

  • The program uses the printf and scanf functions to take input from the user. It prompts the user to enter three numbers one by one, and the values are stored in the respective variables.

Comparison:

  • The program uses a series of if and else if statements to compare the values of num1, num2, and num3 to determine which one is the largest.

Output:

  • The program prints the result to the console using the printf function. It displays the largest number among the three with a message.

End of Program:

  • After printing the result, the program reaches the end of the main function, concluding the program’s execution.
Spread the love
Scroll to Top
Scroll to Top