编写程序,输入n,x,并将0-n的所有Tn(x)值输出到文件tdat.txt中
#include <stdio.h>
#include <stdlib.h>
int main(){
int T(int n, int x);
int x, n;
int i;
int rs;
FILE *fp;
printf("请输入n,x");
scanf("%d,%d", &n,&x);
if((fp = fopen("D://tdat.txt","a+")) == NULL){
printf("文件打开失败");
exit(1);
}
for(i = 0; i <= n; i++)
{
rs = T(i, x);
fprintf(fp,"%d\n",rs);
}
fclose(fp);
}
int T(int n, int x){
if(n == 0)
return 0;
else if( n == 1)
return x;
else{
return 2*x*T( n -1, x) - T(n - 2, x);
}
}