问题 问答题

请编写函数fun(),该函数的功能是:统计各年龄段的人数。N个年龄通过调用随机函数获得,并放在主函数的age数组中。要求函数把0至9岁年龄段的人数在d[0]中,把10至19岁年龄段的人数放在d[1]中,把20至29岁年龄段的人数放在 d[2]中,依次类推,把100岁(含100)以上年龄的人数都放在d[10]中。结果在主函数中输出。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio. h>
# define N 50
# define M 11
void fun(int *a, int *b)

double rnd()

static t=29, c=217,m=1024, r=0;
r= (r*t+c)%m;
return ((double) r/m);

main ( )

int age[N], i,d[M];
for(i=0; i<N; i++)
age [i]= (int) (i15*rnd ());
/*产生一个随机的年龄数组*/
printf ("The original data : \n");
for(i=0; i<N; i++)
printf((i+l)%10= =07 "%4d\n":"%4d",
age[i]); /*每行输出10个数* /
printf ("\n\n");
fun (age, d);
for(i=0; i<l0; i++)
printf("%4d---%4d :%4d\n", i*l0,
i*10+9, d[i] );
printf("Over 100 : %4dkn",d[10]).;

答案

参考答案:

void fun(int *a, int *b)

{

int i,j;

for (j=0; j<M; j++)

b [j]=0; /*数组b初始化为0*/

for (i=0; i<N; i++)

if (a [i]>=A00)

b[A0]++; /*如果年龄大于等于A00,b[A0]自增A*/

else

b[a[i]/A0]++; /*如果年龄小于A00,则将其分别统计到b[a[i]/A0]中*/

}

解析:

本题又是一个分段函数的问题,还是用两个循环来完成。第1个循环的作用是使b的所有元素值都为0。这个循环不能省略,因为若未对b元素赋初值,则它们的值是不可预测的。第2个循环的作用是分别统计a中各年龄段的人数。当a[i]大于等于100时,按题意要将其统计到b[10]中,else的作用是如果年龄小于100,则将其分别统计到b[a[i]/10]中。由运算优先级可知先进行a[i]/10的运算所得结果作为b的下标。若a[i]为0至9时,a[i]/10的值为0,且0至9岁的人数正好要存入b[0]中。若a[i]为10至19岁时a[i]/10的值为1,且10至19岁的人数正好要存入b[1]中,依次类推。

阅读理解

Warner Brothers is an American company that produces movies and television shows. It started as a small family business operated by four brothers — Harry, Albert, Sam and Jack Warner. In nineteen-oh-three, the brothers began their business by traveling throughout Ohio and Pennsylvania showing movies using a projector (放映机). By nineteen-oh-seven, they opened a movie theater in New Castle, Pennsylvania. Within ten years, the Warner brothers started producing movies, and moved that part of the business to California.

  In nineteen eighteen, their first complete picture was called “My Four Years in Germany.” The film was based on a book by the United States’ ambassador to the court of Kaiser Wilhelm. In nineteen twenty-five, they began to work to include the technology for sound in their movies.

  Two years later, Warner Brothers Pictures released the first major movie with sound, or “talking picture.” It was called “The Jazz Singer” and it was a huge success. In the nineteen thirties, the company made several films that were highly praised, including “Little Caesar,” “The Public Enemy”, “The Gold Diggers” and “Forty-Second Street.”

  The Warner Brothers’ success continued in the nineteen forties with movies like “The Maltese Falcon,” and “Casablanca.” Movies during this time starred popular actors like Ingrid Bergman, Humphrey Bogart, James Cagney, Gary Cooper and Bette Davis. The company continues to produce popular movies today.

  By the nineteen seventies, the Warner Brothers studios had also become well set up in television. In nineteen ninety, Warner Communications combined with Time Incorporated to form Time Warner Incorporated.

In two thousand one, the company combined with America Online. The company now includes film production, cable television networks, music and publishing. This year, the company announced a deal with the CBS Corporation to form a new television broadcast network. The CW began broadcasting this month.

小题1:According to the text, at the beginning of their business the four brothers __________.

A.started a movie theater

B.started to produce films

C.were projectionists

D.settled their business in California小题2:The Warner Brothers produced its first talking picture in ___________.

A.1918

B.1925

C.1927

D.1930小题3:According to the text, which of the following is not sound film?

A.The Maltese Falcon

B.Casablanca

C.Forty-Second Street

D.My Four Years in Germany小题4:We can see from the text that ___________.

A.The Warner Brothers has closed.

B.The Warner Brothers has expanded(扩张) its business greatly since it was set up.

C.The CW doesn’t belong to the Warner Brothers.

D.People in the U.S. can’t buy music records produced by the Warner Brothers.

单项选择题 A2型题