c - 尝试用 C 语言运行程序

标签 c

有人可以帮我运行这个程序吗?我试过这个:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void) {
    double Cateto1;
    double Cateto2;
    double hipotenusa;

    printf("dame el primer cateto: ");
    scanf("%1f", Cateto1);
    fflush(stdout);

    printf("dame el segundo cateto: ");
    scanf("%1f", &Cateto2);
    fflush(stdout);

    hipotenusa = sqrt ((Cateto1*Cateto1)+(Cateto2*Cateto2));

    printf("hipotenusa= %2f",hipotenusa);
    system("pause");
}

我可以构建它,但无法运行它......它给了我:

RUN FAILED (exit value -1.073.741.790, total time: 17s)

最佳答案

scanf("%lf", Cateto1);
        ↑    ↑
        |    You are missing a '&' character here
        The width specifier for doubles is l, not 1

scanf 的第一个参数必须是"%lf"(如字母 L),以指定相应的输出变量是指向 double 而不是 float 的指针。 '1'(一)对于 scanf 没有任何意义。

这里 scanf 的第二个参数应该是一个指向 double 的指针,而你给它的是一个 double 。
我认为这是一个简单的拼写错误,因为您第二次就正确了。

关于c - 尝试用 C 语言运行程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19297494/

相关文章:

清除一个字符数组 c

c - 无效参数读写文件

c - pthread_create 仅当套接字上有数据可用时

c - 用 C 编写的开源链接器

c - C 中 for 循环的基本问题

c - 无法理解表达式如何变得错误

c - 带终止和不带终止的两个不同 while 循环之间的区别?

Java 到 C 的交叉编译

c - 递归反向链表而不使用任何新变量

C 字符串问题。输入整数N和字符串,我想打印第N个位置的字符。 (如果 N>strlen(str))