Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

Trying to run a program in C

Can someone help me to run this program? I tried this:

#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");
}

I can build it but I can't run it... it gives me:

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

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

The first argument to scanf must be "%lf" (as the letter L) to specify that the corresponding output variable is a pointer to double instead of a float. '1' (One) has no meaning for scanf.

The second argument to scanf here is expected to be a pointer to double, and you're giving it a double instead.
I suppose it is a simple typo since you got it right the second time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...