C语言上机题库百科园第3章!南信大! 下载本文

内容发布更新时间 : 2024/5/9 8:03:48星期一 下面是文章的全部内容请认真阅读。

}

void main() {

int m;

printf(\ scanf(\

printf(\}

【参考答案】 t+=1.0/i; t=t+1.0/i; 【参考答案】 return t; return (t);

在main函数中,若fun()返回1则输出\若fun()返回0则输出\。 请改正程序中的错误,使它能得出正确的结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: */

#include #include int fun(int m) { int k=2;

while (k<=m&&(m%k))

/**********ERROR**********/ k++

/**********ERROR**********/ if(m=k)

return 1; else return 0; }

void main() { int n;

printf(\scanf(\

if(fun(n)) printf(\ else printf(\}

【参考答案】 k++; k=k+1; ++k;

【参考答案】 if(k==m)

if(m==k)

/*下列给定程序中,函数fun的功能是:判断一个整数m是否是素数,若是返回1,否则返回0。 在main函数中,若fun()返回1则输出\若fun()返回0则输出\。 请改正程序中的错误,使它能得出正确的结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: */

#include #include int fun(int m) { int k=2;

while (k<=m&&(m%k))

/**********ERROR**********/ k++

/**********ERROR**********/ if(m=k)

return 1; else return 0; }

void main() { int n;

printf(\scanf(\

if(fun(n)) printf(\ else printf(\}

【参考答案】 k++; k=k+1; ++k;

【参考答案】 if(k==m) if(m==k)

程序填空

1121231234?1?????23353573579/*已知如下公式:

?

下面程序的功能使根据上述公式输出满足精度要求的eps的?值,请填空使程序完整。*/

#include #include int main ( ) {

double s=0.0,eps,t=1.0;

int n ;

scanf (\

for (n=1 ; t>=fabs(eps); n++) {

s+=t ;

/**********FILL**********/ t= [1] ; }

/**********FILL**********/ [2] ; return 0; }

【参考答案】 t*n/(2*n+1) 【参考答案】 printf(\printf(\

/*请补充main函数,该函数的功能是:打印出满足个位的数字、十位上的数字和百位上的数字都相等的所有三位数。

本题的结果为: 111 222 333 444 555 666 777 888 999。 注意:部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在main函数的横线上填入所编写的若干表达式或语句。 试题程序:*/

#include #include void main() {

int g, s, b;

for(g=1; g<10; g++) for (s=1; s<10; s++) for(b=1; b<10; b++) {

/**********FILL**********/ if( )

/**********FILL**********/ printf(\ } }

【参考答案】 g==s&&s==b

g==b&&s==b g==s&&g==b 【参考答案】 g+s*10+b*100 b*100+s*10+g g+10*s+100*b 100*b+10*s+g 100*g+10*s+b g*100+s*10+b

/*函数fun的功能是:从三个形参a、b、c中找出中间的数,作为函数值返回。 例如,当a=3,b=5,c=4时,中间的数为4。 注意:部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。 试题程序:*/

#include

int fun(int a,int b,int c) { int t;

/**********FILL**********/

t=(a>b)?(b>c?b:(a>c?c:【1】)) /**********FILL**********/ :((a>c)?【2】

/**********FILL**********/ :((b>c)?c:【3】)); return t; }

void main() {

int a1=3,a2=5,a3=4,r; r=fun(a1,a2,a3);

printf(\}

【参考答案】

t=(a>b)?(b>c?b:(a>c?c:a)) 【参考答案】 :((a>c)?a 【参考答案】 :((b>c)?c:b));

/*请补充main函数,该函数的功能是:计算两个自然数n和m(m<10000)之间所有数的和(n和m从键盘输入)。

例如,当n=1,m=100时,sum=5050;当n=100,m=1000时,sum=495550。 注意:部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在main函数的横线上填入所编写的若干表达

式或语句。 试题程序:*/

#include #include void main() {

int n,m; long sum;

/**********FILL**********/ [1] ;

printf(\ scanf(\ while(n<=m) {

/**********FILL**********/ [2] ; n++; }

/**********FILL**********/

printf(\}

【参考答案】 sum=0; 【参考答案】 sum+=n; sum=sum+n; 【参考答案】 ld

/*请补充main函数,该函数的功能是:打印出1-1000中满足个位数字的立方等于其本身所有数。

本题的结果为:1 64 125 216 729 注意:部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在函数main的横线上填入所编写的若干表达式或语句。 试题程序:*/

#include #include void main() {

int i,g;

for(i=1;i<1000;i++) {

/**********FILL**********/ g= [1] ;