English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

in this if condition while cheking greatest of two numbers a value only printed irrespective of their value. If b is greater again a only printed. why is it so? help me to find out the hidden concept. Thank you.

2007-06-18 19:22:33 · 2 answers · asked by Kannan 1 in Science & Mathematics Mathematics

#include
#include
main()
{
int a,b;
clrscr();
printf("enter the value for a:");
scanf("%d",&a);
printf("enter the value for b:");
scanf("%d",&b);
if(a-b)
{
printf("a is greater");
printf("\nThe value of a is:%d",a);
}
else
{
printf("b is greater");
printf("\nThe value of b is:%d",b);
}
getch();
}

2007-06-18 19:30:41 · update #1

2 answers

What is this (a-b) thing? Something is missing from the first if statement there, it doesn't make sense.

But i have a feeling that you try to print the greatest of two numbers, right? If so, then just modify the first if statement by replacing (a-b) with (a>b). It should work. Oh, and don't forget to check the case when the two numbers are equal.

2007-06-18 20:57:18 · answer #1 · answered by Anonymous · 0 0

we need to see the rest of the code, including the print statement.

2007-06-19 02:26:27 · answer #2 · answered by Philo 7 · 0 2

fedest.com, questions and answers