当前位置:文档之家› C语言填空题

C语言填空题

《一》

#include "stdio.h"
int fun(int n)
{
int i;
/***********found1**********/
for (i=2; i<=
____; i++)
/***********found2**********/
if (___________)
return 0;
return 1;
}

main()
{int i,n=0;
/***********found3**********/
for (i=100; ______; i--)
if (fun(i))
{printf("%5d",i);
n++;
}
printf("\n");
}


#include "stdio.h"
int fun(int n)
{
int i;
/***********found1**********/
for (i=2; i<=n-1; i++)
/***********found2**********/
if (n%i==0)
return 0;
return 1;
}

main()
{int i,n=0;
/***********found3**********/
for (i=100; n<5; i--)
if (fun(i))
{printf("%5d",i);
n++;
}
printf("\n");
}
《二》

程序blank8-1.cpp的作用是求一个整除的位数n,请把程序中的下划线_____删除,填入合适的内容.
#include "stdio.h"
void fun(int a, int *p)
{
int n=0;
while(a)
{n++;
a=a/10;
}
/******************/
_________=n;
}
main()
{
int x,n;
printf("请输入一个整除:");
scanf("%d",&x);
/******************/
fun(_______________);
printf("%d共有%d位数\n",x,n);
}


#include "stdio.h"
void fun(int a, int *p)
{
int n=0;
while(a)
{n++;
a=a/10;
}
/******************/
*p=n;
}
main()
{
int x,n;
printf("请输入一个整除:");
scanf("%d",&x);
/******************/
fun(x,&n);
printf("%d共有%d位数\n",x,n);
}
《三》

给定程序的功能是对a数组中n个人员的工资进行分段统计,各段的人数存到b数组中:工资为1000元以下的人数存到b[0]中,工资为1000到1999元的人数存到b[1],工资为2000到2999元的人数存到b[2],工资为3000到3999元的人数存到b[3],工资为4000到4999元的人数存到b[4],工资为5000到5999元的人数存到b[5]中。
例如,当a数组中的数据为:900、1800、2700、3800、5900、3300、2400、7500、3800,调用该函数后,b中存放的数据应是:1、1、2、3、0、2。
请在程序的下划线处填入正确的内容并把下划线删除,使得程序得出正确的结果。
注意:源程序存放在考生文件夹下的blank3.cpp中。不得增行或删行,也不得更改程序的结构!
#include
void fun(int a[], int b[], int n)
{
int i;
/**************found1**************/
for (i=0; i<6; i++) b[i] = ___1___;
for (i=0; iif (a[i] >= 5000) b[5]++;
/**************found2**************/
___2___ b[a[i]/1000]++;
}

main()
{ int i, a[100]={ 900, 1800, 2700, 3800, 5900, 3300, 2400, 7500, 3800}, b[6];
fun(a, b, 9);
printf("The result is: ");
/**************found3**************/
for (i=0; i<6; i++) printf("%d ", ___3___);
printf("\n");
}

#include
void fun(int a[], int b[], int n)
{
int i;
/**************found1**************/
for (i=0; i<6; i++) b[i] =0;
for (i=0; i

i++)
if (a[i] >= 5000) b[5]++;
/**************found2**************/
else b[a[i]/1000]++;
}

main()
{ int i, a[100]={ 900, 1800, 2700, 3800, 5900, 3300, 2400, 7500, 3800}, b[6];
fun(a, b, 9);
printf("The result is: ");
/**************found3**************/
for (i=0; i<6; i++) printf("%d ",b[i]);
printf("\n");
}

《四》

给定程序的功能是对a数组中n个人员的工资进行分段统计,各段的人数存到b数组中:工资为1000元以下的人数存到b[0]中,工资为1000到1999元的人数存到b[1],工资为2000到2999元的人数存到b[2],工资为3000到3999元的人数存到b[3],工资为4000到4999元的人数存到b[4],工资为5000到5999元的人数存到b[5]中。
例如,当a数组中的数据为:900、1800、2700、3800、5900、3300、2400、7500、3800,调用该函数后,b中存放的数据应是:1、1、2、3、0、2。
请在程序的下划线处填入正确的内容并把下划线删除,使得程序得出正确的结果。
注意:源程序存放在考生文件夹下的blank3.cpp中。不得增行或删行,也不得更改程序的结构!
#include
void fun(int a[], int b[], int n)
{
int i;
/**************found1**************/
for (i=0; i<6; i++) b[i] = ___1___;
for (i=0; iif (a[i] >= 5000) b[5]++;
/**************found2**************/
___2___ b[a[i]/1000]++;
}

main()
{ int i, a[100]={ 900, 1800, 2700, 3800, 5900, 3300, 2400, 7500, 3800}, b[6];
fun(a, b, 9);
printf("The result is: ");
/**************found3**************/
for (i=0; i<6; i++) printf("%d ", ___3___);
printf("\n");
}

#include
void fun(int a[], int b[], int n)
{
int i;
/**************found1**************/
for (i=0; i<6; i++) b[i] =0;
for (i=0; iif (a[i] >= 5000) b[5]++;
/**************found2**************/
else b[a[i]/1000]++;
}

main()
{ int i, a[100]={ 900, 1800, 2700, 3800, 5900, 3300, 2400, 7500, 3800}, b[6];
fun(a, b, 9);
printf("The result is: ");
/**************found3**************/
for (i=0; i<6; i++) printf("%d ",b[i]);
printf("\n");
}

《五》
给定程序的功能是求出1到1000之内能被7或11整除但不能同时被7和11整除的所有整数放在数组a中,通过n返回这些数的个数。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的blank4.cpp中。请不要更改下划线以外的任何内容,否则将可能不得分
不得增行或删行,也不得更改程序的结构!

#include
void fun(int *a, int *n)
{
int i, j = 0 ;

for(i = 1 ; i <= 1000 ; i++) {
if(((i % 7 == 0) || (i % 11 == 0)) && i % 77 != 0)
/**************found1**************/
a[j++] = ___1___ ;
}
/**********

****found2**************/
*n =___2___ ;
}

main()
{ int aa[1000], n, k ;
/**************found3**************/
fun (aa,___3___ ) ;
for ( k = 0 ; k < n ; k++ )
if((k + 1) % 10 == 0)
printf("\n") ;
else
printf("%5d", aa[k]) ;
}


#include
void fun(int *a, int *n)
{
int i, j = 0 ;

for(i = 1 ; i <= 1000 ; i++) {
if(((i % 7 == 0) || (i % 11 == 0)) && i % 77 != 0)
/**************found1**************/
a[j++] =i ;
}
/**************found2**************/
*n =j ;
}

main()
{ int aa[1000], n, k ;
/**************found3**************/
fun (aa,&n ) ;
for ( k = 0 ; k < n ; k++ )
if((k + 1) % 10 == 0)
printf("\n") ;
else
printf("%5d", aa[k]) ;
}
《六》

程序 blank7.cpp的作用是对两个数字型字符串转化成两个整数后相加,请填空完成任务。
如输入: 1234 2345 结果为: 3579

#include
#include
#include
#define N 9
long ctod( char *s )
{ long d=0;
while(*s)
if(isdigit( *s))
{
/**********found1**********/
d=d*10+*s-__1__;
/**********found2**********/
__2__;
}
return d;
}
long fun( char *a, char *b )
{
/**********found3**********/
return __3__;
}
NONO();
main()
{ char s1[N],s2[N];
do
{ printf("Input string s1 : "); gets(s1); }
while( strlen(s1)>N );
do
{ printf("Input string s2 : "); gets(s2); }
while( strlen(s2)>N );
printf("The result is: %ld\n", fun(s1,s2) );
NONO();
}




#include
#include
#include
#define N 9
long ctod( char *s )
{ long d=0;
while(*s)
if(isdigit( *s))
{
/**********found1**********/
d=d*10+*s-48;
/**********found2**********/
s++;
}
return d;
}
long fun( char *a, char *b )
{
/**********found3**********/
return ctod(a)+ctod(b);
}
NONO();
main()
{ char s1[N],s2[N];
do
{ printf("Input string s1 : "); gets(s1); }
while( strlen(s1)>N );
do
{ printf("Input string s2 : "); gets(s2); }
while( strlen(s2)>N );
printf("The result is: %ld\n", fun(s1,s2) );
NONO();
}
《七》

给定程序的功能是把s串中所有的字母改写成该字母的下一个字母,字母Z改写成字母a。大写字母仍为大写字母,小写字母仍为小写字母,其它字符不变。
例如:s串中原有的字符串为:Mn.123Zxy,则调用该函数后,s串中的内容为:No.123Ayz.
请在程序的 下划线处填入正确的内容并把下划线删除,使程序得出正确结果
注意:源程序存放在考生文件夹下的BLANK.C中。不得增行或删行,也不得更改程序的结构
#include
#include
#include
#define N 81
fun ( char *s )
{
/**************found1**************/
char *p = ___1___

;

while(*p)
{
if(*p == 'Z')
/**************found2**************/
*p = ___2___ ;
else if(*p == 'z')
/**************found3**************/
*p = ___3___ ;

else if(isalpha(*p)) *p = (*p) + 1 ;
p++ ;
}
}
main( )
{ char a[N];
printf ( "Enter a string : " );
gets ( a );
printf ( "The original string is : " );
puts( a );
fun ( a );
printf ( "The string after modified : ");
puts ( a );
}


#include
#include
#include
#define N 81
fun ( char *s )
{
/**************found1**************/
char *p =s ;

while(*p)
{
if(*p == 'Z')
/**************found2**************/
*p = 'A';
else if(*p == 'z')
/**************found3**************/
*p = 'a' ;

else if(isalpha(*p)) *p = (*p) + 1 ;
p++ ;
}
}
main( )
{ char a[N];
printf ( "Enter a string : " );
gets ( a );
printf ( "The original string is : " );
puts( a );
fun ( a );
printf ( "The string after modified : ");
puts ( a );
}






相关主题
文本预览
相关文档 最新文档