In this article, we are going to write a C program that identifies the greatest number among three numbers.
Table of Contents
Problem Statement- WAP to find the greatest of three numbers.
Significance of Finding the Greatest
Identifying the largest number among a group is a crucial operation in programming. It is essential for various applications, ranging from sorting algorithms to decision-making processes in everyday software.
C Program to Find Greatest Among Three Numbers
#include <stdio.h>
void main()
{
int n1, n2, n3;
printf("Enter the first number ");
scanf("%d", &n1);
printf("Enter the second number ");
scanf("%d", &n2);
printf("Enter the third number ");
scanf("%d", &n3);
int greatest = n1;
if (n2 > greatest)
{
greatest = n2;
}
if (n3 > greatest)
{
greatest = n3;
}
printf("The greatest number is = %d", greatest);
}
Output
The above C program finds the greatest number among three numbers by using the else statement, This problem statement is a valuable exercise that combines user interaction, decision-making, and basic arithmetic.
Happy Coding
3 thoughts on “Finding the Greatest Among Three Numbers”