Sunday, 24 February 2013

To Check which number is Greater by using if . . . else


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the value of a and b");
scanf("%d%d",&a,&b);
if(a>=b)
{
printf("a is Greater");
}
else
{
printf("b is Greater");
}
getch();
}

Output
Enter the value of a and b
4
7
b is Greater

1 comment:

  1. This is stupidly trivial and still plain wrong.

    1) Return value of scanf() is not checked. So if the user enters text instead of numbers, what happens? Sure not what is intended.

    2) Enter the same number twice. It would still says that one is greater than the other.

    ReplyDelete