问题 问答题

规定输入的字符串中只包含字母和*号。编写函数fun,其功能是:删除字符串中所有的*号。编写函数时,不得使用C语言提供的字符串函数。
例如,字符串中的内容为“****A*BC*DEF*G*******”,删除后,字符串中的内容应当是“ABCDEFG”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
void fun(char*a)


voidmain()

char s[81];
printf("Enter a string:\n");
gets(s);
fun(s);
printf("The string after delete&\n");
puts(s);

答案

参考答案:

void fun(char*a)

{

int i,j=0;

for(i=0;a[i]!=’\0’;i++)

if(a[i]!=’*’)

a[j++]=a[i]; /*若不是要删除的字符’*’则留下*/

a[j]=’\0’;

}

解析:

用循环操作从字符串的开始往后逐个进行比较,若不是要删除的字符(用if(a[i]!=’*’)来控制)则保留。变量i和j用来表示原字符串的下标和删除*号后新字符串的下标。注意下标变量j要从0开始,最后还要加上字符串结束标识’\0’。

阅读理解

阅读理解。

     What makes people happier:money or having happy friends and neighbors? Scientists have found

an answer as part of a study.    

     The new study found that friends of happy people had a greater chance of being happy themselves.

And the smaller the distance between friends,the larger the effect they had on each other's happiness.      

     For example,a person was 20% more likely to feel happy if a friend who lived within  l. 5 kilometers.

Having a happy neighbor who lived next door increased the chance of being happy by 34%. The effects

of friends' happiness lasted for up to a year.      

    The scientists found that sadness also spread among friends,but not as much as happiness.      

     People who take 3 degrees out of' separation still had an effect on a person's happiness.3 degrees

of separation means the friend of a friend of a friend.      

     The study showed that having an extra 5 ,000 dollars increased a person's chances of becoming

happier by about 2 percent. But the researchers found that the influence of a friend of a friend of a

friend can be greater than that.

1. The effects of happiness from friends ____.    

A. have a chance of 20%  to make you happy    

B. are usually within l.5km    

C. have a chance of 34% to make you happy    

D.can last about a year

2. The word "spread" in the fourth paragraph means in China?    

A. 传播    

B. 流行    

C. 分享    

D. 兴盛

3. Having a happy friend who lives within one and a half kilometers increases a chance of being

    happy by____.

A. 45%    

B. 50%    

C. 34%    

D. 20%

4. Which of the followings has the greatest effect on happiness according to the passage?    

A. Money.    

B. The friend of a friend.    

C. Happy friends who live in another city.    

D. Happy neighbors.

5. From this passage we know ____.  

A. who's the happiest  

B. what's happiness  

C. what makes people happier  

D. how to make people happy

填空题