问题 问答题

请编写函数fun(),该函数的功能是:计算并输出
S=1+(1+20.5)+(1+20.5+30.5)+…+(1+20.5+30.5+…+n0.5)
例如,若主函数从键盘给n输入20后,则输出为
s=534.188884。
注意;部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在函数fun 的花括号中填入所编写的若干语句。
试题程序:
#include <math. h>
#include <stdio. h>
double fun(int n)
{
}
main()
{
int n;
double s;
printf("\n\nInput n: ");
scanf ("%d", &n);
s=fun (n)
printf ("\n\ns=%f\n\n", s);
}

答案

参考答案:

解析:double fun(int n)
{
int i;
double s=0.0,s1=0.0;
for(i=1;i<=n; i++)
{s1=s1+pow(i,0.5); /*求每—项*/
s=s+s1; /*按公式求出s*/
}
return s;
}
我们先用数学的思路读懂该程序,并用1个字符表示“()”内的值。在本程序中用s1来表示题中每个小括号内的值,第1项相当于有1个10.5次方(它还是1),第2项相当于第1项的值加上200.5次方,第3项相当于第2项的值加上30.5次方,…,依次类推。函数pow (x,y)的功能是求出x的y次方,该函数已在库函数<math. h>中定义(即可直接使用)。要程序中用s来表示总的结果,每1次循环加1次s1即加1项。

完形填空

When Lewis Hamilton crossed the finishing line in the last F1 race of 2008, he said to his team over the team radio, "Do I have it? Do I have it? I am too happy!” He really couldn’t believe that he became the youngest F1 World Champion, and the first black man to win it.

In 2007, Lewis entered the Fl world. His talent(天赋) for racing and his performances soon amazed everyone. He did a great job in his first fifteen races. But the last two races were nightmares(恶梦). He lost them, and lost the world champion title in the end by just one point.

2008 was a hard year for Lewis. Many Fl fans criticized(责难) him, and most F1 racers didn't talk to him any more. He was lonely. But his wish to win kept him strong. He raced very well., and had a seven-point lead before the last race in Brazil. He won 4 points from this race, just enough to win the world champion title.

There's no reason he can't win a lot more.

小题1:What did Lewis say when he won the F1 race of 2008?

________________________________________________________________________

小题2: When did Lewis start his F1 world? What did people think of him?

________________________________________________________________________

小题3: In 2007, he lost the F1 race, didn't he?

________________________________________________________________________

小题4: How did he do before the last race in Brazil?

________________________________________________________________________

小题5: 请将文中画线的句子翻译成汉语。

________________________________________________________________________

单项选择题