C Program to Find the Greatest Number Among Input Three Numbers
Using “if” statement
#include<stdio.h>
#include<conio.h>
main()
{
int
a,b,c;
printf("Enter
three numbers\n");
scanf("%d
%d %d",&a, &b, &c);
if(
a>b && a>c)
printf("a
is greatest and the number is %d",a);
if(b>c
&& b>a)
printf("b
is greatest and the number is %d",b);
if(c>a
&& c>b)
printf("
c is greatest and the number is %d",c);
getch();
}
Using if…else if statement
#include<stdio.h>
#include<conio.h>
main()
{
int
a,b,c;
printf("Enter
three numbers\n");
scanf("%d
%d %d",&a, &b, &c);
if(
a>b && a>c)
printf("a
is greatest and the number is %d",a);
else
if(b>c)
printf("b
is greatest and the number is %d",b);
else
printf("
c is greatest and the number is %d",c);
getch();
}
Output:
No comments:
Post a Comment