gpt4 book ai didi

c 程序。下面的错误是什么意思

转载 作者:行者123 更新时间:2023-11-30 21:43:29 25 4
gpt4 key购买 nike

||=== Build: Debug in 78 pp (compiler: GNU GCC Compiler) ===|

||In function 'main':|

|3|error: expected identifier or '(' before 'int'|

|8|warning: format '%f' expects argument of type 'double', but argument 2 has
type 'int' [-Wformat=]|

|9|error: 'big' undeclared (first use in this function)|

|9|note: each undeclared identifier is reported only once for each function it
appears in|

|11|error: 'i' undeclared (first use in this function)|

|19|warning: control reaches end of non-void function [-Wreturn-type]|

||=== Build failed: 3 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===|

源代码:

#include<stdio.h>
int main(){
int n,num,int i;
printf("Enter the values of n: ");
scanf("%d",&n);
printf("Number %f",1);
scanf("%d",big);
for(i=2;i<n;i++){
printf("Number %df: ",i);
scanf("%d",&num); if(big<num) big=num;
}
printf("%d",big);
}

最佳答案

错误1:预期标识符或“int”之前的“(”

变量 n、num 和 i 的声明有错误。我认为你把 , 代替 ;所以替换为

int n,num;
int i;

int n, num, i;

警告2:格式“%f”需要“double”类型的参数,但参数 2 的类型为“int”[-Wformat=]

%f 意味着它需要浮点型,您已经传递了 1 (int)。所以替换为6

printf("Number %d", 1);

甚至

printf ("Number 1"); 

因为它是一个常数。

错误3:未声明“big”(在此函数中首次使用)

未声明 Big。因此添加 int big; (假设它是因为您使用 %d 扫描的)。稍后会出现的另一个问题是您在需要 int* 的地方传递了 int 。因此将 scanf 调用替换为

scanf("%d",&big);

错误4:'i' 未声明(在此函数中首次使用

将通过解决Error1来解决。

警告5:控制到达非 void 函数的末尾 [-Wreturn-type]

main 声明为返回类型 int 但不返回任何内容

添加

return 0; 

最后表示程序成功终止。如果程序未成功退出,请将 0 替换为任何其他错误代码。

关于c 程序。下面的错误是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42711213/

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