第31题 (10.0分) 难度:易 第20章
/*-------------------------------------------------------
【程序填空】
---------------------------------------------------------
功能:下面程序是计算 sum=1+(1+1/2)+(1+1/2+1/3)+...
(1+1/2+...1/n)的值。
例如:当n=3,sum=4.3333333
-------------------------------------------------------*/
#include <stdio.h>
double f(int n)
{
int i;
double s;
s=0;
for(i=1;i<=n;i++)
/***********SPACE***********/
【?】;
return s;
}
main()
{
int i,m=3;
double sum=0;
for(i=1;i<=m;i++)
/***********SPACE***********/
【?】;
/***********SPACE***********/
printf("【?】\n",sum);
}
答案:
=======(答案1)=======
s+=1.0/i
=========或=========
s+=1/i
=========或=========
s= s + 1.0/i
=========或=========
s= s + 1/i
=======(答案2)=======
sum+=f(i)
=========或=========
sum= sum + f(i)
=======(答案3)=======
%lf
第32题 (10.0分) 难度:易 第91章
/*-------------------------------------------------------
【程序填空】
---------------------------------------------------------
题目:某等差数列的第一项a=2,公差d=3。
下面程序的功能是在前n(1≤n≤10)项和中,
输出所有项的和能被4整除者。请填空。
-------------------------------------------------------*/
#include <stdio.h>
void main()
{
int a,d,sum,n,i;
/***********SPACE***********/
a=2; d=3;i=1;sum=【?】;
scanf("%d",&n);
do{
sum+=a;
i++;
/***********SPACE***********/
【?】;
/***********SPACE***********/
if(【?】)
printf("%d\n",sum);
}while(i<=n);
}
答案:
=======(答案1)=======
0
=======(答案2)=======
a+=d
=========或=========
a+=3
=========或=========
a=a+d
=========或=========
a=a+3
=======(答案3)=======
sum%4==0
第33题 (10.0分) 难度:易 第1章
/*-------------------------------------------------------
【程序填空】
---------------------------------------------------------
题目:从键盘键盘输入3个整数,然后找出最小的数并输出。
例如:输入"10,41,31",
输出 "三个数是:10,41,31.最小数是:10."。
-------------------------------------------------------*/
#include <stdio.h>
#include <conio.h>
main()
{
int a, b, c, min;
printf("请输入三个整数:\n");
/***********SPACE***********/
scanf("%d,%d,%d",【?】);
printf("三个数是:%d,%d,%d.", a, b, c);
if (a > b) min=b; else min=a;
/***********SPACE***********/
if (【?】) min=c;
/***********SPACE***********/
printf("最小数是:【?】", min);
}
答案:
=======(答案1)=======
&a, &b, &c
=======(答案2)=======
min>c
=========或=========
min>=c
=========或=========
c<min
=========或=========
c<=min
=======(答案3)=======
%d.
第34题 (10.0分) 难度:易 第1章
/*-------------------------------------------------------
【程序填空】
---------------------------------------------------------
题目:下列给定程序中,函数fun的功能是:将形参n中,各位上为偶数的数取出,并按原
来从高位到低位相反的顺序组成一个新数,作为函数值返回。
例如:输入一个整数27638496,函数返回值为64862。
-------------------------------------------------------*/
#include <stdio.h>
unsigned long fun(unsigned long n)
{
unsigned long x=0; int t;
while(n)
{
t=n%10;
/***********SPACE***********/
if(t%2==【?】)
/***********SPACE***********/
x=【?】+t;
/***********SPACE***********/
n=【?】;
}
return x;
}
main()
{
unsigned long n=-1;
while(n>99999999||n<0)
{
printf("Please input(0<n<100000000): ");
scanf("%ld",&n);
}
printf("\nThe result is: %ld\n",fun(n));
}
答案:
=======(答案1)=======
0
=======(答案2)=======
10*x
=========或=========
x*10
=======(答案3)=======
n/10
第35题 (10.0分) 难度:易 第1章
/*-------------------------------------------------------
【程序填空】
---------------------------------------------------------
题目:输入一个5位数,判断它是不是回文数。
例如12321是回文数,即个位与万位相同,
十位与千位相同。请填空。
-------------------------------------------------------*/
#include <stdio.h>
void fun(long x)
{ long ge,shi,qian,wan;
wan=x/10000;
/***********SPACE***********/
qian=【?】;
/***********SPACE***********/
shi=【?】;
ge=x%10;
/***********SPACE***********/
if (【?】)
printf("this number is a huiwen\n");
else printf("this number is not a huiwen\n");
}
void main()
{
fun(12321);
}
答案:
=======(答案1)=======
x%10000/1000
=========或=========
x/1000%10
=======(答案2)=======
x%100/10
=========或=========
x/10%10
=======(答案3)=======
ge==wan&&shi==qian
=========或=========
wan==ge&&shi==qian
=========或=========
ge==wan&&qian==shi
=========或=========
wan==ge&&qian==shi
第36题 (10.0分) 难度:易 第1章
/*-------------------------------------------------------
【程序填空】
---------------------------------------------------------
功能:下面的程序是求1!+3!+5!+……+n!的和。
-------------------------------------------------------*/
#include <stdio.h>
main(){
long int f,s;
int i,j,n;
/***********SPACE***********/
【?】;
scanf("%d",&n);
/***********SPACE***********/
for(i=1;i<=n; 【?】) {
f=1;
/***********SPACE***********/
for(j=1; 【?】;j++)
/***********SPACE***********/
【?】;
s=s+f;
}
printf("n=%d,s=%ld\n",n,s);
}
答案:
=======(答案1)=======
s=0
=======(答案2)=======
i+=2
=========或=========
i=i+2
=======(答案3)=======
j<=i
=========或=========
i>=j
=========或=========
i+1>j
=========或=========
j<i+1
=======(答案4)=======
f=f*j
=========或=========
f*=j
=========或=========
f=j*f
第37题 (10.0分) 难度:易 第1章
/*-------------------------------------------------------
【程序填空】
---------------------------------------------------------
题目:函数fun的功能是:统计长整数n的各位上出现数字1、2、3的次数,并用
外部(全局)变量c1、c2、c3返回主函数。
例如:当n=123114350时,结果应该为:c1=3 c2=1 c3=2。
-------------------------------------------------------*/
#include <stdio.h>
int c1, c2, c3;
void fun(long n)
{
c1=c2=c3=0;
while(n)
{
/***********SPACE***********/
switch(【?】)
{
case 1:
/***********SPACE***********/
c1++;【?】;
case 2:
/***********SPACE***********/
c2++;【?】;
case 3:
c3++;
}
n/=10;
}
}
main()
{
long n=123114350L;
fun(n);
printf("\nThe result: \n");
printf("n=%ld c1=%d c2=%d c3=%d\n",n,c1,c2,c3);
}
答案:
=======(答案1)=======
n%10
=======(答案2)=======
break
=======(答案3)=======
break
第38题 (10.0分) 难度:易 第2章
/*-------------------------------------------------------
【程序填空】
---------------------------------------------------------
功能:不用第三个变量,实现两个数的对调操作。
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,b;
scanf("%d %d",&a,&b);
printf("a=%d,b=%d\n",a,b);
/***********SPACE***********/
a= 【?】 ;
/***********SPACE***********/
b= 【?】 ;
/***********SPACE***********/
a= 【?】 ;
printf("a=%d,b=%d\n",a,b);
}
答案:
=======(答案1)=======
a + b
=======(答案2)=======
a-b
=========或=========
a -b
=======(答案3)=======
a-b
=========或=========
a -b
第39题 (10.0分) 难度:易 第2章
/*-------------------------------------------------------
【程序填空】
---------------------------------------------------------
功能:识别输入的字符串,每个单词输出一行
-------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
void main()
{
int c;
int inspace;
/***********SPACE***********/
【?】;
while((c = getchar()) != '\n')
{
if(c == ' ' || c == '\t' || c == '\n')
{
/***********SPACE***********/
if(【?】)
{
inspace = 1;
putchar('\n');
}
}
else
{
inspace = 0;
/***********SPACE***********/
【?】;
}
}
}
答案:
=======(答案1)=======
inspace = 0
=======(答案2)=======
inspace == 0
=======(答案3)=======
putchar(c)
第40题 (10.0分) 难度:易 第1章
/*-------------------------------------------------------
【程序填空】
---------------------------------------------------------
题目:下列给定程序中,函数fun的功能是:找出100~999之间(含100和999)所有整数中各
位上数字之和为x(x为正整数)的整数,并输出;符合条件的整数个数作为函数值返回。
例如:当x值为5时,100~999之间各位上数字之和为5的整数有:104、113、122、131、
140、203、212、221、230、302、311、320、401、410、500,共有15个。
当x值为27时,各位数字之和为27的整数是:999,只有1个。
-------------------------------------------------------*/
#include <stdio.h>
int fun(int x)
{
int n, s1, s2, s3, t;
n=0;
t=100;
/***********SPACE***********/
while(t<=【?】)
{
s1=t%10;
/***********SPACE***********/
s2=(【?】)%10;
s3=t/100;
/***********SPACE***********/
if(s1+s2+s3==【?】)
{
printf("%d ",t);
n++;
}
t++;
}
return n;
}
main()
{
int x=-1;
while(x<0)
{
printf("Please input(x>0): ");
scanf("%d",&x);
}
printf("\nThe result is: %d\n",fun(x));
}
答案:
=======(答案1)=======
999
=======(答案2)=======
t/10
=======(答案3)=======
x