C语言用数组做递归的问题。
#include<stdio.h>#include<stdlib.h>intmain(){intn,m,r,j;intf[10000]={0,1,2,3};while(1...
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,m,r,j;
int f[10000]= {0,1,2,3};
while(1)
{
printf("Please Input N and M:");
scanf("%d%d",&n,&m);
if(n==0&&m==0)
exit(0);
while(m<2||n>10000||m>10000)
{
printf("Please Input Conrect Numbers:");
scanf("%d%d",&n,&m);
}
for(j=4; j<=n; j++)
{
f[j]=f[j-1]%m+f[j-3]%m;
}
r = f[n]%m;
printf("%d\n",r);
}
return 0;
}
求大神指出错误。。 展开
#include <stdlib.h>
int main()
{
int n,m,r,j;
int f[10000]= {0,1,2,3};
while(1)
{
printf("Please Input N and M:");
scanf("%d%d",&n,&m);
if(n==0&&m==0)
exit(0);
while(m<2||n>10000||m>10000)
{
printf("Please Input Conrect Numbers:");
scanf("%d%d",&n,&m);
}
for(j=4; j<=n; j++)
{
f[j]=f[j-1]%m+f[j-3]%m;
}
r = f[n]%m;
printf("%d\n",r);
}
return 0;
}
求大神指出错误。。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询