gpt4 book ai didi

C 程序给出太多参数警告

转载 作者:行者123 更新时间:2023-12-02 07:31:17 25 4
gpt4 key购买 nike

所以我有这段代码,我尝试解决一些简单的数学问题:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

float ruutvorrand(float a, float b, float c);

int main(void) {
float a;
float b;
float c;
float solution;

printf("Ruutvõrrandi lahedamine\nSisesta andmed: ");
scanf("%f %f %f", &a, &b, &c);
solution = ruutvorrand(a, b, c);
printf("Ruutvõrrandi lahendid on: ", solution);
return 0;
}

float ruutvorrand(float a, float b, float c) {
float out;
float upper;
float upper1;
upper = sqrt((b * 2)-(4 * a * c));
upper1 = (-b + upper);
out = upper1 / (2 * a);
return out;
}

问题是当我尝试编译它时出现此错误:

gcc yl3.c -o ruut -lmyl3.c: In function ‘main’:
yl3.c:16:5: warning: too many arguments for format [-Wformat-extra-args]
printf("Ruutvõrrandi lahendid on: ", solution);

现在我在这里做错了什么。我真的给函数提供了太多参数吗?

最佳答案

您忘记了 printf 中的格式字符串:

printf("Ruutvõrrandi lahendid on: ", solution);

应该是:

printf("Ruutvõrrandi lahendid on: %f", solution);
// ^ %f because soulution in float

关于C 程序给出太多参数警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21460728/

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