C program to find the greatest number among four numbers | My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Wednesday, June 26, 2019

C program to find the greatest number among four numbers | My CS Tutorial


In this tutorial we will learn how write a C program that find the greatest number among four numbers.
We will write a C program that find the biggest number among four numbers.

Solution:

  • In this program we will use two header files.
  • In this program we will use four variables a,b, c and d.
  • We declared these four variables a,b,c and d in int data type.
  • Then we will enter the value of a,b,c and d.
  • We will use if else statement with some conditions which is (a>b),(a>c) and (b>c) and more.
  • And after it we will print the statement or body.
  • When we use these statement the condition execute own statement.
  • When the if condition is false it execute else statement.


C program code


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d;
clrscr();

printf("\n Enter the value of a=");
scanf("%d",&a);

printf("\n Enter the value of b=");
scanf("%d",&b);

printf("\n Enter the value of c=");
scanf("%d",&c);

printf("\n Enter the value of d=");
scanf("%d",&d);

if(a>b)
{
if(a>c)
{
if(a>d)
printf(" a is greatest");
else
printf(" d is greatest");
}
}
else
if(b>a)
{
if(b>c)
{
if(b>d)
printf(" b is greatest");
else
printf(" d is greatest");
}
}
else
if(c>a)
{
if(c>b)
{
if(c>d)
printf(" c is greatest");
else
printf(" d is greatest");
}
}
getch();
}



Output 1:





Output 2:







we will find the greatest number among four numbers so we take four variables a,b,c and d and use the if else statement.
We use some conditions to find the greatest number.

  When we use if or else statement inside a if statement or else statement this is called nesting of if else statement.


I hope that you understand everything easily.If you have any problem or question so you write a comment and follow me on this blog and my Facebook page and on Instagram.Share the post.

No comments:

Post a Comment