#include<stdio.h>
int main() {
int m,n;
float cake;
printf("Enter total kgs of cake:");
scanf("&d", &n);
printf("Enter the number of friends:");
scanf("&d", &m);
cake = m/n;
printf(He has to distribute %f kg cake to each of his %d friends",
&cake, &m);
}
当我在代码块中运行这个程序时,它只要求我输入蛋糕的总公斤数,当我输入它并单击输入时,程序只打印下面 printf 函数中的所有其他内容,而不是要求我输入好友数量。
最佳答案
scanf("&d", &n);
scanf("&d", &m);
您需要将其更改为
scanf("%d", &n);
scanf("%d", &m);
此外,在 printf 函数中,您不应传递变量的地址
关于C 程序输出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43764335/