C 程序输出错误

标签 c

#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/

相关文章:

将 float 转换为 int 会改变值

c - C 中负数的环礁值

c - C 程序,可处理 3 位数字,但无法处理 5 位数字

c - 解析带有奇数标记的 C 字符串

代码从 C 文本文件中读取几行

c - 如何使用 win32 API 获取链接标签的句柄

c++ - wchar_t 数据是否需要字节序转换?

c - gettimeofday 可能无法在 C 中获得正确的时间

c - 如何将 `pthread_t` 反向映射(哈希)到结构指针?

c++ - 动态调整组合框的宽度,以便显示整个字符串