C program to find the largest(greatest) number between two 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(greatest) number between two numbers | My CS Tutorial

In this C program we will learn how write a C program that find the greatest number between two numbers.


Solution:


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


C program code


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("\n Enter the value of a=");
scanf("%d",&a);

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

if(a>b)
{
printf("\n a is greater than b.");
}
else
if(a==b)
{
printf("\n a is equal to b.");
}
else
{
    printf("\n a is less than b.");
}
getch();
}


Output 1:




Output 2:





Output 3:





we will find the greatest number between two numbers so we take two variables a and b 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