问题 填空题

以下sum函数的功能是计算下列级数之和。


请给函数中的各变量正确赋初值。
double sum(double x,int n)
int i;double a,b,s;
【20】
for(i=1;i<=n;i++)
a=a*x;b=b*i;s=s+a/b;
return s;

答案

参考答案:a=1;b=1;s=1;(说明:语句的顺序可任意)或a=b=s=1;(说明:变量的顺序可任意)或a=1,b=1,s=1(说明:赋值表达式的顺序可任意)给a,b,s赋1或1.0或1.都可以

解析:sum函数的功能是求表达式s的级数之和,其思路为:在该函数中,定义了一个整型变量i用作循环计数器,定义一个变量a用来表示各个子项的分子,初始为第一个子项的分子,故为1,定义了一个变量b用来表示各个子项大分母,初始为第一个子项的分母,故为1,定义一个变量s存放累加和s初始为第一个子项的值即为1,然后给各个定义的变量初始化,然后通过一个for循环将题目中的数学表达式的各个子项求出来并累加到 s中,因此,在该题的空格处应该填写将a、b和s赋初值的语句,即为a=1;b=1;s=1;(说明:语句的顺序可任意)或a=b=s=1;(说明:变量的顺序可任意)或a=1,b=1,s=1 (说明:赋值表达式的顺序可任意)给a,b,s赋1或1.0或1.都可以。

阅读理解

Have you ever taken a color test? It isn’t like a normal test because you don’t pass or fail it. You choose your favorite color from a list and then a computer will tell you your personality(个性). If you like red, you may like to take risks(冒险). If you like pink, you are a peaceful person.
Some large companies(公司)and universities(大学)use color tests to decide if somebody is going to be a hard worker. Some doctors use them to get a quick idea of the problems that a patient may have.
Choose your favorite color below. Then you will know what kind of person you are.
Color
    Personality
Red
Energetic(精力旺盛)
Yellow
Happy and relaxed
Green
Don’t like changes
Blue
Calm
Black
Stubborn(固执)
小题1:When you are taking a color test, ____________________.
A. you may fail it   B. you must pass it   C. a computer will tell you your personality
小题2: If a person like blue, he ____________________.
A. always feels tired        B. is usually very calm        C. is always very happy
小题3:Jane has a chance to go abroad, but she refuses. What color does Jane perhaps like?
A. Black                 B. Blue                     C. Green
小题4:If someone is peaceful, he may like ______________.
A. blue                  B. pink                      C. Yellow
小题5:According to the passage, color tests are usually used by(被┅使用) ___________.
A. doctors, large companies and universities   B. doctors, patients and universities
C. doctors, patients, large companies and universities.
选择题