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)
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.
Here is the mistake:
scanf("%1f", Cateto1);
Change it to:
scanf("%1f", &Cateto1);
There is an Error in your code. Instead of
scanf("%1f", Cateto1);
you should write:
scanf("%1f", &Cateto1);
简单的错误
scanf("%1f", &Cateto1); // '&' was missing in all scanf statements
#include <stdio.h>
#include <math.h>
int main(void)
{
double Cateto1;
double Cateto2;
double hipotenusa;
printf("dame el primer cateto: ");
scanf("%lf", &Cateto1);
//fflush(stdout);
printf("dame el segundo cateto: ");
scanf("%lf", &Cateto2);
//fflush(stdout);
hipotenusa = sqrt ((Cateto1*Cateto1)+(Cateto2*Cateto2));
printf("hipotenusa= %2f\n",hipotenusa);
//system("pause");
return 0;
}
There are a couple of errors:
scanf
expression was wrong: "%1f" should be "%lf" Cateto1
( &Cateto1
) to scanf
fflush
system
call Here's the updated code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void) {
double Cateto1;
double Cateto2;
double hipotenusa;
printf("dame el primer cateto: ");
scanf("%lf", &Cateto1);
printf("dame el segundo cateto: ");
scanf("%lf", &Cateto2);
hipotenusa = sqrt ((Cateto1*Cateto1)+(Cateto2*Cateto2));
printf("hipotenusa= %2f\n",hipotenusa);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.