sum*=sum问题
#include"stdio.h"int main (void)
{int j,k,o;
long int sum=1,i[4];
printf("\n\n\n\n");
printf("%32s\n\n","::::: 乘 方 表 :::::");
printf("%5s%7s%7s%9s%9s\n%5s%7s%7s%8s%9s\n\n",
"整数","平方","立方","四次方","五次方",
"-----","-----","-----","-----","-----");
printf("请输入一个整数:");
scanf("%d",&o);
for(j=1;j<=o;j++){
sum=j;
for(k=0;k<=3;k++){
sum*=sum;
i[k]=sum;};
printf("%5u%7u%7u%8u%9u\n",
j,i[0],i[1],i[2],i[3]);};
getchar();}
程序运行时平方和四次方的值为0;
是不是sum*=sum那条语句有问题,但是我不知道为什么错了.
[此贴子已经被作者于2007-2-1 17:30:55编辑过]
搜索更多相关的解决方案:
sum
----------------解决方案--------------------------------------------------------
以下是引用cyclone14在2007-2-1 17:25:58的发言:
#include"stdio.h"
int main (void)
{int j,k,o;
long int sum=1,i[4];
printf("\n\n\n\n");
printf("%32s\n\n","::::: 乘 方 表 :::::");
printf("%5s%7s%7s%9s%9s\n%5s%7s%7s%8s%9s\n\n",
"整数","平方","立方","四次方","五次方",
"-----","-----","-----","-----","-----");
printf("请输入一个整数:");
scanf("%d",&o);
for(j=1;j<=o;j++){
sum=j;
for(k=0;k<=3;k++){
sum*=sum;
i[k]=sum;};
printf("%5u%7u%7u%8u%9u\n",
j,i[0],i[1],i[2],i[3]);};
getchar();}
程序运行时平方和四次方的值为0;
是不是sum*=sum那条语句有问题,但是我不知道为什么错了.
#include"stdio.h"
int main (void)
{int j,k,o;
long int sum=1,i[4];
printf("\n\n\n\n");
printf("%32s\n\n","::::: 乘 方 表 :::::");
printf("%5s%7s%7s%9s%9s\n%5s%7s%7s%8s%9s\n\n",
"整数","平方","立方","四次方","五次方",
"-----","-----","-----","-----","-----");
printf("请输入一个整数:");
scanf("%d",&o);
for(j=1;j<=o;j++){
sum=j;
for(k=0;k<=3;k++){
sum*=sum;
i[k]=sum;};
printf("%5u%7u%7u%8u%9u\n",
j,i[0],i[1],i[2],i[3]);};
getchar();}
程序运行时平方和四次方的值为0;
是不是sum*=sum那条语句有问题,但是我不知道为什么错了.
去掉long
----------------解决方案--------------------------------------------------------
我的编译器能通过呀?
#include"stdio.h"
int main (void)
{
int j,k,o;
long int sum=1,i[4];
printf("\n\n\n\n");
printf("%32s\n\n","::::: 乘 方 表 :::::");
printf("%5s%7s%7s%9s%9s\n%5s%7s%7s%8s%9s\n\n",
"整数","平方","立方","四次方","五次方",
"-----","-----","-----","-----","-----");
printf("请输入一个整数:");
scanf("%d",&o);
for(j=1;j<=o;j++)
{
sum=j;
for(k=0;k<=3;k++)
{
sum*=sum;
i[k]=sum;
}
printf("%5u%7u%7u%8u%9u\n",
j,i[0],i[1],i[2],i[3]);
}
getchar();
return 0;
}
----------------解决方案--------------------------------------------------------
人家也没说是语法问题
----------------解决方案--------------------------------------------------------
去掉LONG以后也不对撒...
----------------解决方案--------------------------------------------------------
怎么不对?
----------------解决方案--------------------------------------------------------
哦
我忘了说了
还有一个地方得改
for(k=0;k<=3;k++)
{
sum*=j;
i[k]=sum;
}
----------------解决方案--------------------------------------------------------