存在两个数字x
和y
,使得x! + 是啊! = 10!
以及一个名为 solve10
的方法,该方法返回数组中的值 x
和 y
( a[0 ] == x,a[1] == y 和 x!+ y!= 10!
)
我的代码
int * solve10()
{
int fact=1;
printf("Enter two elements");
scanf("%d",&x,&y);
for(int i=0;i<x;i++){
intx1=fact*i;
}
for(int i=0;i<y;i++){
inty1=fact*i;
}
//check condition
if(x1+y1=10!){
//how to retrun x in a[0] ie a[0]=x and a[1]=y
int a[][]={x,y}
}
}
我该如何解决这个问题,请给我提示
最佳答案
您将必须使用嵌套循环。
int p = fact(10);
for(int i = 1; i <= 10; i++){
for(int j = 1; j <= 10; j++){
if(fact(i) + fact(j) == p){
a[0] = i;
a[1] = j;
return a;
}
}
}
您可以实现事实函数,该函数将用于计算整数的阶乘。
关于c - 将输入放入数组c程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36420655/