计算机二级c语言上机 - 程序填空题(3)

2019-05-24 08:04

/**************found**************/ fun ( ___2___ ) ;

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

{ for (j = 0 ; j < n ; j++)

/**************found**************/ printf ( \ printf ( \

第一空:a[j][k] 第二空:a,n 第三空:a[i][j]

39.给定程序的功能是对a数组中n个人员的工资进行分段统计,各段的人数存到b数组中;工资为1000元以下的人数存到b[0]中, 工资为1000元到1999元的人数存到b[1]中, 工资为2000元到2999元的人数存到b[2], 工资为3000元到3999元的人数存到b[3], 工资为4000元到4999元的人数存到b[4],工资为5000元以上的人数存到b[5]中。例如,当a数组中的数据为:900、1800、2700、3800、5900、3300、2400、7500、3800,调用该函数后,b中存放的数据应是:1、1、2、3、0、2 #include

void fun(int a[], int b[], int n) { int i;

/**************found**************/ for (i=0; i<6; i++) b[i] = ___1___; for (i=0; i

if (a[i] >= 5000) b[5]++;

/**************found*************/ ___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(\

/**************found**************/ for (i=0; i<6; i++)

printf(\ printf(\

第一空:0 第二空:else 第三空:b[i]

40.给定程序的功能是将n个人员的考试成绩进行分段统计,考试成绩放在a数组中,各分数段的人数存到b数组中:成绩为60到69的人数存到b[0], 成绩为70到79的人数存到b[1], 成绩为80到89的人数存到b[2], 成绩为90到99的人数存到b[3],成绩为100的人数存到b[4],成绩为60分以下的人数存到b[5]中。例如,当a数组中的数据是:93、85、77、68、59、43、94、75、98。调用该函数后,b数组中存放的数据应是:1、2、1、3、0、2。 #include

void fun(int a[], int b[], int n) { int i;

for (i=0; i<6; i++) b[i] = 0;

/**************found**************/ for (i=0; i< ___1___; i++) if (a[i] < 60) b[5]++;

/**************found**************/ ___2___ b[(a[i]- 60)/10]++;} main() { int i, a[100]={ 93, 85, 77, 68, 59, 43, 94, 75, 98}, b[6];

/**************found**************/ fun(___3___, 9);

printf(\

for (i=0; i<6; i++) printf(\ printf(\

第一空:n 第二空:else 第三空:a,b

41.给定程序的功能是求出1到1000之内能被7或11整除但不能同时被7和11整除的所有整数放存数组a中,通过n返回这些数的个数。 #include void fun(int *a, int *n) { int i, j = 0 ;

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

/**************found**************/

if(((i % 7 == 0) || (i % 11 == 0)) && i % 77 != 0) a[j++] = ___1___ ; }

/**************found**************/ *n = ___2___ ;} main()

{ int aa[1000], n, k ;

/**************found**************/ fun ( ___3___ ) ;

for ( k = 0 ; k < n ; k++ )

if((k + 1) % 10 == 0) printf(\ else printf(\第一空:i 第二空:j 第三空:aa,&n

42.给定程序中已经建立一个带有头结点的单向链表,在main函数中将多次调用fun函数,每调用一次fun函数,输出链表尾部结点中的数据,并释放该结点,使链表缩短。

#include #include #define N 8 typedef struct list { int data;

struct list *next; } SLIST;

void fun( SLIST *p) { SLIST *t, *s;

t=p->next; s=p; while(t->next != NULL) { s=t;

/**********found**********/ t=t->___1___; }

/**********found**********/ printf(\ s->next=NULL;

/**********found**********/ free(___3___);}

SLIST *creatlist(int *a)

{ SLIST *h,*p,*q; int i;

h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; i

{ q=(SLIST *)malloc(sizeof(SLIST)); q->data=a[i]; p->next=q; p=q;} p->next=0; return h;}

void outlist(SLIST *h) { SLIST *p; p=h->next;

if (p==NULL) printf(\ else

{ printf(\

do{printf(\ p=p->next; } while(p!=NULL);

printf(\main(){ SLIST *head;

int a[N]={11,12,15,18,19,22,25,29}; head=creatlist(a);

printf(\ outlist(head);

printf(\while (head->next != NULL){ fun(head); printf(\printf(\from head again :\\n\outlist(head); }}

第一空:next 第二空:t->data 第三空:t

43.给定程序的功能是计算score中m个人的平均成绩aver,将低于aver的成绩放在below中,通过函数名返回人数。例如,当

socre={10,20,30,40,50,60,70,80,90},m=9时,函数返回的人数应该是4,below={10,20,30,40}。 #include #include

int fun(int score[], int m, int below[]) { int i, j = 0 ; float aver = 0.0 ;

for(i = 0 ; i < m ; i++) aver += score[i] ; aver /= (float) m ; for(i = 0 ; i < m ; i++)

/**************found**************/

if(score[i] < aver) below[j++] = ___1___ ; return j ;}

main(){ int i, n, below[9] ;

int score[9] = {10, 20, 30, 40, 50, 60, 70, 80, 90} ;

/**************found**************/ n = fun(score, 9, ___2___) ;

printf( \/**************found**************/

for (i = 0 ; i < n ; i++) printf(\第一空:score[i] 第二空:below 第三空:below[i]

44.给定程序的功能是求出能整除x且不是偶数的各整数,并放在数组pp中,这些除数的个数由n返回。例如,若x的值为30,则有4个数符合要求,它们是1,3,5,15。 #include void fun(int x, int pp[], int *n) { int i, j = 0 ;

for(i = 1 ; i <= x ; i +=2 )

/**************found**************/ if((x % i) == 0) pp[j++] = ___1___ ; /**************found**************/ *n = ___2___ ;}

main(){ int x, aa[1000], n, i ;

printf( \enter an integer number:\\n\) ; scanf(\

/**************found**************/ fun(x, ___3___ ) ;

for( i = 0 ; i < n ; i++ ) printf(\ printf(\

第一空: i 第二空: j 第三空:aa,&n

45.已知学生的记录由学号和学习成绩构成,N名学生的数据已经存入a结构体数组中。给定程序的功能是找出成绩最低的学生记录,通过形参返回主函数。 #include #include #define N 10 typedef struct ss

{ char num[10]; int s; } STU; fun(STU a[], STU *s)

{/**************found**************/ ___1___ h; int i ; h = a[0];

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

/**************found**************/ if ( a[i].s < h.s ) ___2___ = a[i]; /**************found**************/ *s = ___3___ ;}

main(){STU a[N]={ {\

{\ {\{\ ; int i;

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

printf(\ Mark = %d\\n\ fun ( a, &m );

printf (\ RESULT *****\\n\

printf (\ : %s , %d\\n\ 第一空:STU 第二空:h 第三空:h

46.给定程序中已经建立一个带有头结点的单项链表,链表中的各结点按照数据域递增有序链接。函数fun的功能是:函数链表中数据域值相同的结点,使之只保留一个。

#include #include #define N 8 typedef struct list { int data;

struct list *next;

} SLIST;

void fun( SLIST *h) { SLIST *p, *q; p=h->next; if (p!=NULL) { q=p->next;

while(q!=NULL)

{ if (p->data==q->data) { p->next=q->next; /**********found**********/ free(___1___); /**********found**********/ q=p->___2___; } else { p=q;

/**********found**********/ q=q->___3___; } } }} SLIST *creatlist(int *a)

{ SLIST *h,*p,*q; int i;

h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; i

{ q=(SLIST *)malloc(sizeof(SLIST)); q->data=a[i]; p->next=q; p=q; } p->next=0; return h;}

void outlist(SLIST *h) { SLIST *p; p=h->next; if (p==NULL)

printf(\ else{ printf(\

do{printf(\ p=p->next; } while(p!=NULL);

printf(\main( ){ SLIST *head; int a[N]={1,2,2,3,4,4,4,5}; head=creatlist(a);

printf(\list before deleting :\\n\outlist(head); fun(head); printf(\list after deleting :\\n\outlist(head);}

第一空:q 第二空:next 第三空: next

47.给定程序的功能是实现矩阵(3行3列)的转置。#include int fun(int array[3][3]) { int i,j,arr[3][3] ;

memcpy(arr, array, 9*sizeof(int)) ; for(i = 0 ; i < 3 ; i++) for(j = 0 ; j < 3 ; j++)

/**************found**************/ array[i][j] = ___1___ ;} main(){ int i,j;

int array[3][3]={{100,200,300}, {400,500,600}, {700,800,900}}; for (i=0;i<3;i++)

{ for (j=0;j<3;j++)

printf(\ printf(\

/**************found**************/ fun(___2___);

printf(\ for (i=0;i<3;i++)

{ for (j=0;j<3;j++)

/**************found**************/ printf(\ printf(\

第一空:arr[j][i] 第二空:array 第三空:array[i][j] 48.函数fun的功能是:统计长整数n的各个位上出现数字1、2、3的次数,并通过上部(全局)变量 c1、c2、c3返回主函数。例如:当n=123114350时,结果应该是:c1=3 c2=1 c3=2。 #include int c1,c2,c3; void fun(long n) { c1 = c2 = c3 = 0; while (n) {

/**********found**********/ switch(___1___){

/**********found**********/ case 1: c1++;___2___; /**********found**********/ case 2: c2++;___3___; case 3: c3++; }

n /= 10;}}

main(){ long n=123114350L;

fun(n); printf(\

printf(\ c1=%d c2=%d c3=%d\\n\n,c1,c2,c3);}

第一空:n 第二空:break 第三空:break

49.函数fun的功能是进行字母转换,若形参ch中小写英文字母,则转换成参应的大写英文字母;若ch中是大写英文字母,则转换成对应的小写英文字母;若是其它字母则保持不变;并转换后的结果作为函数值返回。#include #include char fun(char ch)

{/**********found**********/ if ((ch>='a')___1___(ch<='z')) return ch -'a' + 'A'; if ( isupper(ch) )

/**********found**********/ return ch +'a'-___2___ ; /**********found**********/ return ___3___;} main(){ char c1, c2;

printf(\ :\\n\ c1='w'; c2 = fun(c1);

printf(\ c2=%c\\n\ c1='W'; c2 = fun(c1);

printf(\ c2=%c\\n\ c1='8'; c2 = fun(c1);

printf(\ c2=%c\\n\第一空:&& 第二空:?A? 第三空:ch

50.给定程序的功能是对指定字符在字符串a中出现的次数进行统计,统计的数据存到b数组中。其中:字符?Z? 出现的次数存放到b[0]中,字符?Y?出现的次数存放到b[1],字符?X?出现的次数存放到b[2]中,字符?W?出现的次数存放到b[3],字符?V?出现的次数存放到b[4]中,其它字符出现的次数存到b[5]中。 #include #include

void fun(char *a, int b[]) { int i;

for (i=0; i<6; i++) b[i] = 0;

/**************found**************/ for (i=0; i< ___1___(a); i++)

if (a[i] >= 'V' && a[i] <= 'Z') b[4-(a[i]-'V')]++;

/**************found**************/ ___2___ b[5]++;} main()

{ int i, b[6];

char a[100] = \/**************found**************/ fun(___3___);

printf(\

for (i=0; i<6; i++) printf(\ printf(\

第一空:strlen 第二空:else 第三空:a,b

50.函数fun的功能是:将形参a所指数组中的前半部分元素中的值和后半部分元素中的值对换。形参n中存放数组中的数据的个数,若n为奇数,则中间的元素不动。例如:若a所指数组中的数据一次为:1、2、3、4、5、6、7、8、9,则调换后为:6、7、8、9、5、1、2、3、4。

#include #define N 9

void fun(int a[], int n) { int i, t, p;

/**********found**********/

p = (n%2==0)?n/2:n/2+___1___; for (i=0; i

/**********found**********/ a[i] = a[p+___2___]; /**********found**********/ ___3___ = t; }} main()

{ int b[N]={1,2,3,4,5,6,7,8,9}, i;

printf(\ :\\n\ for (i=0; i

第一空:1 第二空:i 第三空:a[p+i]

52.给定程序的功能是把s串中所有的字符前移一个位置,串中的第一个字符移到最后。例如:s串中原有的字符串为:Mn.123xyZ,则调用函数后,s串中的内容为:n.123xyZM

#include #define N 81 fun ( char *s ) { char b[N] ;

sprintf(b, \

/**************found**************/ strcpy(___1___) ;} main( )

{ char a[ N ] ;

printf ( \ a string : \ printf ( \ \/**************found**************/ fun ( ___2___ );

printf ( \ \/**************found**************/ ___3___ ( a );}

第一空:s,b 第二空:a 第三空:puts

53.给定程序的功能是计算并输出high以内最大的10个素数和。high由主函数传给fun函数。例如:high值为100,函数的值为732。 #include #include int fun( int high )

{ int sum = 0, n=0, j, yes;

/************found************/ while ((high >= 2) ___1___ (n < 10)) { yes = 1;

for (j=2; j<=high/2; j++ ) if (high % j ==0 ){

/************found************/ yes=0; ___2___; }

if (yes) { sum +=high; n++; } /************found************/ ___3___; } return sum ;} main ( ){

printf(\

第一空:&& 第二空:break 第三空:high=high-1 54.给定程序的功能是删除w数组中下标为k的元素中的值。程序中,调用了getindex、arrout和arrdel三个函数,getindex用以输入所删除元素的下标,函数中对输入的下标进行检查,若越界,则要求重新输入,直到正确为止。arrout用以输出数组中的数据,arrdel进行所要求的删除操作。 #include #define NUM 10 arrout ( int *w, int m )

{ int k;

/************found************/ for (k = 0; k < ___1___; k++) printf (\ printf (\

arrdel ( int *w, int n, int k ) { int i;

for ( i = k; i < n-1; i++ ) w[i] = w[i+1]; n--;

/************found************/ return ___2___;} getindex( int n ) { int i;

/************found************/ ___3___

{ printf(\ scanf (\

} while( i < 0 || i > n-1 ); return i;} main( )

{ int n, d,

a[NUM]={21,22,23,24,25,26,27,28,29,30}; n = NUM;

printf (\ arrout ( a, n );

d = getindex( n ); n = arrdel ( a, n, d );

printf (\ arrout( a, n );}

第一空:m 第二空:n 第三空: do

55.给定程序的功能是从字符串s尾部开始,按逆序把在其中出现的每相邻的两个字符,紧随其后重复出现一次,放在一个新串t中,若字符串s中头部有剩余的单个字符也重复,放在t的最后。例如:当s中的字符串为:”12345”时,则t中的字符串应该为:”5454323211” #include #include

void fun (char *s, char *t) { int i, j, sl; sl = strlen(s);

for(i=sl-1,j=0;i>=0;i-=2) { t[j++] = s[i];

if (i-1 >= 0) t[j++] = s[i-1]; /************found************/ t[j++] = ___1___;

/************found************/ if (i-1 ___2___ 0) t[j++]=s[i-1]; } t[j] = '\\0';} main()

{ char s[100], t[100];

printf(\/************found************/ fun(___3___);

printf(\第一空:s[i] 第二空:>= 第三空:s,t 56. 给定程序的功能是建立一个带有头结点的单向链表,并用随机函数为各结点赋值。函数fun的功能是将单向链表结点(不包括结点)数据域为偶数的值累加起来,并且作为函数值返回。 #include #include typedef struct aa

{ int data; struct aa *next; }NODE; int fun(NODE *h) { int sum = 0 ;

/***********found**********/ ___1___ *p;

/***********found**********/ p=___2___; while(p)

{ if(p->data%2==0) sum +=p->data;

/***********found**********/ p=___3___; } return sum;}

NODE *creatlink(int n) { NODE *h, *p, *s, *q; int i, x;

h=p=(NODE *)malloc(sizeof(NODE)); for(i=1; i<=n; i++)

{ s=(NODE *)malloc(sizeof(NODE)); s->data=rand(); s->next=p->next; p->next=s; p=p->next; } p->next=NULL; return h;}

outlink(NODE *h, FILE *pf) { NODE *p; p = h->next;

fprintf(pf ,\ LIST :\\n\\n HEAD \ while(p)

{ fprintf(pf ,\ fprintf (pf,\outresult(int s, FILE *pf)

{fprintf(pf,\ %d\\n\main(){ NODE *head; int even; head=creatlink(12); head->data=9000; outlink(head , stdout); even=fun(head);

printf(\ result :\\n\ outresult(even, stdout);}

第一空:NODE 第二空:h->next 第三空:p->next 57.给定程序的功能是把在字符串s中出现的每个字符,紧随其后重复出现一次,形成一个新串放在t中,且在t中把原相邻字符的位置进行了互换。例如:当s中的字符串为:”12345”时,则t中的字符串应该为:”2211443355”。 #include #include


计算机二级c语言上机 - 程序填空题(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:《统计学原理》习题集

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: