0
What is the mistake in this code to find greater value only using if in c prgrm
2 odpowiedzi
+ 2
GEOWIN B VARGHESE there was 2 mistakes
1. You didn't used '&' sign before the variable in the scanf() function, this may not case problems in some compilers but its better to try using them this way.
2. In the if condition you missed to add bracket to the overall condition.
+ 5
Your first mistake you forget address of operator (&) in all scanf u have to write like this
scanf("%d",& number);
_________________________________
*Second mistake you have to put one more round bracket around all if statements
like
if((fn>sn)&&(fn>tn)&&(fn>frn))
__________________________________
See this i fixed your code its working properly.
#include <stdio.h>
int main()
{
int fn,sn,tn,frn;
printf("/n Enter first number:");
scanf("%d",&fn);
printf("/n Enter second number:");
scanf("%d",&sn);
printf("/n Enter third number:");
scanf("%d",&tn);
printf("/n Enter four number:");
scanf("%d",&frn);
if((fn>sn)&&(fn>tn)&&(fn>frn))
{
printf("%d is the greater number",fn);
}
if((sn>fn)&&(sn>tn)&&(sn>frn))
{
printf("%d is the greater number",sn);
}
if((tn>fn)&&(tn>sn)&&(tn>frn))
{
printf("%d is the greater number",tn);
}
if((frn>fn)&&(frn>sn)&&(frn>tn))
{
printf("%d is the greater number",frn);
}
}