2道c语言作业(回答正确再加50分)

来源:百度知道 编辑:UC知道 时间:2024/05/18 00:22:23
1.用下面的公式计算e的x次方。在程序中要求用函数f1计算每项分子的值,用函数f2计算每项分母的值(用递归函数来实现)。通过主函数调用f1和f2完成计算。
=1+ x + x*x/2! +x*x*x/3! + …(前10项的和)
2. 编写函数fun(char s[ ], int num[ ]),其功能是统计字符串 s 中数字字符、大写字母、小写字母和空格字符的出现次数,统计结果存于num数组中。再设计main函数,调用fun函数,实现预期功能。
编译有错误

1.

int f1(int t, int x)
{
if (t==0) return 1;
else return x * f1(t-1,x);
}

int f2(int t)
{
if (t==0) return 1;
else return t * f2(t-1);
}

void main()
{
int t=0, x;
float result = 0.0;
float temp;
printf("please input x\n");
scanf("%d",&x);
while(t<10)
{
temp = (float)f1(t,x) / (float)f2(t);
result += temp;
t++;
}
printf("result is %f",result);
}

2.

void fun(char s[ ], int num[ ])
{

int x=0;
while (s[x]!='\0')
{
if(s[x]>='0'&&s[x]<='9') num[0]++;
if(s[x]>='A'&&s[x]<='Z') num[1]++;
if(s[x]>='a'&&s[x]<='z') num[2]++;
if(s[x] == ' ') num[3]++;
x++;
}
}

void main()