想求两数平方的阶乘和但为什么结果一直是1703716?



```c++
#include<stdio.h>
int square(int a)
{int b;
b=a*a;
return b;
}
int factorial(int x)
{
int z=0;int c=1;
int a[200];
a[0]=1;
for(z;z<=x-1;z++)
{
c*=a[z];
a[z]+=a[z];
}
return c;
}
int main()
{int x;
int y;
int z;
printf("输入两个整数:");
scanf("%d%d",&x,&y);
z=factorial(square(x))+factorial(square(y));
printf("两数平方的阶乘和%d",&z);
return 0;
}




```

img

printf("两数平方的阶乘和%d", z);  //去掉&

计算阶乘的函数也不对,修改如下

#include <stdio.h>
int square(int a)
{
    int b;
    b = a * a;
    return b;
}
int factorial(int x)
{
    int z;
    int c = 1;
    for (z = 1; z <= x; z++)
    {
        c *= z;
    }
    return c;
}
int main()
{
    int x;
    int y;
    int z;
    printf("输入两个整数:");
    scanf("%d%d", &x, &y);
    z = factorial(square(x)) + factorial(square(y));
    printf("两数平方的阶乘和%d", z);  //去掉&
    return 0;
}

如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!

img

  • 29行 去掉取地址符 &
  • 求阶乘的函数你写的不对
int factorial(int x)
{
int c=1;
for(;x>1;x--)
{
c*=x;
}
return c;

img

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632