鱼C论坛

 找回密码
 立即注册
查看: 41|回复: 8

为什么无法运行这个程序

[复制链接]
发表于 4 小时前 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#incude
int main(void)
{
int num;
num=1;
printf("I am a simple");
printf("computer.\n");
printf("my favorite number is %d because it is first.\n,"num);
return 0;
}
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 4 小时前 | 显示全部楼层
你的程序有几个错误,导致无法编译运行:

  • 第一行 #incude 写错了,应该是 #include <stdio.h>,否则系统不认识 printf 函数。
  • 最后的 printf 语句中,格式字符串后面直接跟了 num,中间少了一个逗号。而且字符串里多了一个多余的逗号。正确写法应该是 printf("my favorite number is %d because it is first.\n", num);


修改后的完整代码如下:


  1. #include <stdio.h>

  2. int main(void)
  3. {
  4.     int num;
  5.     num = 1;
  6.     printf("I am a simple");
  7.     printf("computer.\n");
  8.     printf("my favorite number is %d because it is first.\n", num);
  9.     return 0;
  10. }
复制代码


这样程序就能正常编译运行了。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 4 小时前 | 显示全部楼层
哦我少写了字母
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 4 小时前 | 显示全部楼层


是的,你少写了 stdio.h 中的几个字母。第一行正确的写法是:

  1. #include <stdio.h>
复制代码


少了 std.h,所以编译器不认识 printf 函数。

另外,最后一行 printf 的参数之间也少了一个逗号,记得补上哦。改正后就能正常运行了。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 4 小时前 | 显示全部楼层
#include<stdio.h>
int main(void)
{
int num;
num=1;
printf("I am a simple");
printf("computer.\n");
printf("my favorite number is %d because it is first.\n,num");
return 0;
}
改过了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 4 小时前 | 显示全部楼层
刘斩仙 发表于 2026-08-08 16:23
#include<stdio.h>
int main(void)
{
int num;
nu ...


你改过了,但还有一个地方不对。最后一行里,逗号和 num 被写进了字符串里面,这样 %d 就没有对应的参数了。正确的写法是:把逗号和 num 放到字符串外面,作为参数传给 printf

正确代码如下:

  1. #include <stdio.h>
  2. int main(void)
  3. {
  4.     int num;
  5.     num = 1;
  6.     printf("I am a simple");
  7.     printf("computer.\n");
  8.     printf("my favorite number is %d because it is first.\n", num);
  9.     return 0;
  10. }
复制代码


注意最后一行:字符串用双引号结束之后,先写逗号,再写 num,这样才能正确输出。现在再运行就没问题了。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 3 小时前 | 显示全部楼层
  1. #include <stdio.h>

  2. int main(void){
  3.     int num;
  4.     num = 1;
  5.     printf("I am a simple");
  6.     printf("computer.\n");
  7.     printf("my favorite number is %d because it is first.\n,", num);
  8.    
  9.     return 0;
  10. }
复制代码

第一行错了, 应该这样写
第8行printf格式化输出, num前面要加个逗号
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 1 小时前 | 显示全部楼层
为什么我输出的是-2063211968
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 半小时前 | 显示全部楼层
#include<stdio.h>
int main(void)
{
int num;
num=1;
printf("I am a simple");
printf("computer.\n");
printf("my favorite number is %d becuse it is first.\n",num);
return 0;
}
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-8-8 20:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表