解题思路:先利用数学知识,求通项
注意事项:
参考代码:
#include<stdio.h>
int main()
{
int str[30]={'\0'};
int i,n;
str[2]=4;
str[3]=10;
while(scanf("%d",&n)==1)
{
if(n<4)
{
printf("%d\n",str[n]);
}
else
{
for(i=4;i<=n;i++)
{
str[i]=str[i-1]+2*(str[i-1]-str[i-2]);
}
printf("%d\n",str[n]);
}
}
return 0;
}
0.0分
0 人评分