#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#define PI 3.142
main(){
float fn, sn, ans;
printf("Hello, please enter your first number and second number: ");
scanf("%f %f", &fn, &sn);
ans = (fn**sn);
printf("%f", ans);
}
错误输出是在ans =(fn ** sn)的行中需要一个指针; 指针也需要什么。我试图在语句中放入“”,但输出的数字错误,而不是电源os fn和sn。
Unlike in Python,
**
isn't a valid operator in C. The compiler is treating the first*
as multiplication but then it thinks that the second*
is dereferencing a pointer, whichsn
isn't.If you're trying to perform multiplication, use a single
*
. If you're trying to perform exponentiation, usepow
frommath.h
.例如,