+ 5
Can anyone let me know why this code giving garbage output?(solved)
#include <stdio.h> int main() { int fruit,num_of_apples,num_of_pies ; printf ("enter no.of fruits"); scanf ("%d",&fruit); num_of_apples=fruit/2; if(fruit <3) printf ("0"); else num_of_pies = num_of_apples/3; printf("%d",&num_of_pies); return 0; }
2 ответов
+ 3
First, in code coaches or other coding challenge problems, you dont need to print any text or prompt, the problem only needs the output.
And if you want to output the value of a variable, omit the ampersand (&)
// It should be
printf("%d", var)
// And not
printf("%d", &var)
If you need more explanations, please feel free to ask. Thanks.
Code:
https://code.sololearn.com/cHtzejVvZBD0/?ref=app
+ 2
Thank you so much!Eve