Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...