gpt4 book ai didi

C 代码-If 条件 HW

转载 作者:行者123 更新时间:2023-11-30 14:55:06 25 4
gpt4 key购买 nike

我有这段代码,但总是出现段错误,并且无法正确运行:

#include <stdio.h>

void main()
{
int num;

printf("enter the number of words\n");
scanf("%d", num);

if (num > 10) {
printf("a very smart parrot");
}

if (num >= 6 && num <= 10) {
printf ("a smart parrot");
}

if (num > 1 && num <= 5) {
printf ("an average parrot");
}

if (num == 0) {
printf ("a silent parrot");
}
}

最佳答案

您的程序可能在 scanf ("%d", num); 行中断

你必须写

scanf ("%d", &num);

由于函数scanf需要指针作为参数,因此必须指向num的地址才能将读取的值保存到变量中

关于C 代码-If 条件 HW,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46227739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com