想编一个程序表达-1的(n+1)次方, 程序如下:
#include<stdio.h>
int main(void)
{
long x,y,z;
printf("Please enter the x;\n");
scanf("%ld",&x);
for(y=-1;x>0;x--)
y*=(-1);
printf("the y is: %ld.\n");
return 0;
}
运行的结果:
结果为什么会这样呢? 是数据的类型 什么的错了吗? 将 long 改成int 也是一样的错误。