想编一个程序表达-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 也是一样的错误。
输出结果的printf那里,有%,那后边的变量呢?
应该这样:
printf("the y is: %ld.\n",y);
#include<stdio.h>
int main(void)
{
long x,y,z;
printf("Please enter the x;\n");
scanf("%ld",&x);
y=-1;
for(;x>0;x--)
y*=(-1);
printf("the y is: %ld.\n",y);
return 0;
}
你Printf函数里没有传入y的值啊
printf("the y is: %ld.\n",y);
1、12行没输出y。
2、y的初至应该为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",y);
return 0;
}
大意了,谢谢!