Can anyone let me know why this code giving garbage output?(solved) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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; }

29th Apr 2021, 2:14 AM
Hemasri Kottapalli
Hemasri Kottapalli - avatar
2 Answers
+ 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
29th Apr 2021, 3:05 AM
noteve
noteve - avatar
+ 2
Thank you so much!Eve
29th Apr 2021, 3:10 AM
Hemasri Kottapalli
Hemasri Kottapalli - avatar