0

What is the mistake in this code to find greater value only using if in c prgrm

https://code.sololearn.com/cow7E4j5bdl4/?ref=app

30th Aug 2020, 5:09 AM
GEOWIN B VARGHESE
GEOWIN B VARGHESE - avatar
2 Réponses
+ 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.
30th Aug 2020, 5:32 AM
Amal P Franglin
Amal P Franglin - avatar
+ 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); } }
30th Aug 2020, 5:31 AM
A S Raghuvanshi
A S Raghuvanshi - avatar