C program to find the largest number among three 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....

Tuesday, June 25, 2019

C program to find the largest number among three numbers | My CS Tutorial



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

Solution:

  • In this program we will use two header files.
  • In this program we will use three variables a,b and c.
  • We declared these three variables a,b and c in int data type.
  • Then we will enter the value of a and b.
  • We will use if else statement with three conditions which is (a>b),(a>c) and (b>c).
  • 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;
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);

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

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

getch();
}



Output 1:





Output 2:





Output 3:









we will find the greatest number among three numbers so we take three variables a,b and c 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