Program to largest and equal of two numbers

0
7
#include<stdio.h>
#include<conio.h>
void main()
{
   int a,b;      /* for two numbers a & b */
   clrscr();
   printf("Enter the numbers \n");
   scanf("%d%d",&a,&b);
   if(a>b)      /* check for a is largest and gives true 
                      when a is largest otherwise false */
      printf("largest=%d\n",a);
   if(b>a)     /*  check for b is largest and gives true 
                      when b is largest otherwise false  */
       printf("largest=%d\n",b);
   if(a==b)    /*  check for equality of a and b and gives true 
                      when equal otherwise false  */
        printf("both %d and %d are equal\n", a,b);
   getch();
}
   output 1:
   Enter the numbers 
   15 17
   largest=17
   output 2:
   Enter the numbers 
   40 35
   largest=40
   output 3:
   Enter the numbers 
   30 30
   both 30 and 30 are equal
Note:-  In this case we are using conditions three times. It can be solved by just two conditions by the use of if…….else statement.

 

 

Program to largest of two numbers Program to largest and equal of two numbers Program to largest and equal of two numbers in cc Program to largest and equal of two numbers

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here