Member-only story

Greatest of Three Numbers in C Using Nested If

Bipsmedium
2 min readJul 10, 2022

--

Hi friends, in this tutorial you will learn how to write a program to find the greatest of three numbers in c using nested if statement.

The logic of the program:-

  • First of all, we will declare four integer variables as a,b,c, and big. here ‘big’ is used to store the result.
  • Inside the first if condition, We will compare ‘a’ with ‘b’. If ‘a’ is greater than ‘b’ then we will compare ‘a’ to ‘c’. In this case if ‘a’ is greater than ‘c’ then ‘a will be stored to the resultant variable ‘big’. On the other hand, if ‘c’ is greater than ‘a’ then ‘c’ will be stored to the resultant variable ‘big’.
  • Inside the else condition, we will compare ‘b’ with ‘c’. If ‘b’ is greater than ‘c’ then ‘b’ will be stored to the resultant variable ‘big’. On the other hand, if ‘c’ is greater than ‘b’ then ‘c’ will be stored to the resultant variable ‘big’.

Also read, Biggest of Two Numbers in C Language

Example to find the greatest of three numbers in C using nested if statement

#include<stdio.h> 
main()
{
int a,b,c,big;
printf("\n Enter the three numbers: ");
scanf("%d%d%d",&a,&b,&c);
//if condition to compare a and b
if(a>b)
{
//another if condition to a and c
if(a>c)
{
big = a;
}
else
{
big = c;
}
}
else
{
//another if condition to compare b and c
if(b>c)
{
big = b;
}
else
{
big = c;
}
}
printf("\n Biggest number is…

--

--

Bipsmedium
Bipsmedium

Written by Bipsmedium

Hi, This is Biplab and I am a PHP laravel developer and other open source technologies. I am here to share my experience with the community.

No responses yet