程序填空题(3)

2019-05-24 13:54

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 outlist(head); }}

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

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 ;

:\\n\ h = a[0];

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

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

if ( a[i].s < h.s ) ___2___ = a[i];

43.给定程序的功能是计算score中m个人的平均成绩/**************found**************/ aver,将低于aver的成绩放在below中,通过函数名返回 *s = ___3___ ;} 人数。例如,当 main(){STU a[N]={ {\

socre={10,20,30,40,50,60,70,80,90},m=9时,函数返{\回的人数应该是4,below={10,20,30,40}。 {\#include {\#include int i; int fun(int score[], int m, int below[]) printf(\{ int i, j = 0 ; for ( i=0; i< N; i++ ) float aver = 0.0 ; printf(\ for(i = 0 ; i < m ; i++) aver += score[i] ; fun ( a, &m ); aver /= (float) m ; printf (\ for(i = 0 ; i < m ; i++) printf (\/**************found**************/ 第一空:STU 第二空:h 第三空:h

if(score[i] < aver) below[j++] = ___1___ ; 46. 给定程序中已经建立一个带有头结点的单项链表, return j ;} 链表中的各结点按照数据域递增有序链接。函数fun的main(){ int i, n, below[9] ; 功能是:函数链表中数据域值相同的结点,使之只保留 int score[9] = {10, 20, 30, 40, 50, 一个。(101) 60, 70, 80, 90} ; #define N 8 /**************found**************/ typedef struct list n = fun(score, 9, ___2___) ; { int data; printf( \ struct list *next; /**************found**************/ } SLIST; for (i = 0 ; i < n ; i++) printf(\\___3___) ;} void fun( SLIST *h) 第一空:score[i] 第二空:below 第三空:below[i] { SLIST *p, *q;

p=h->next;

44.给定程序的功能是求出能整除x且不是偶数的各整 if (p!=NULL) 数,并放在数组pp中,这些除数的个数由n返回。例如, { q=p->next; 若x的值为30,则有4个数符合要求,它们是1,3,5,15。 while(q!=NULL) #include { if (p->data==q->data) void fun(int x, int pp[], int *n) { p->next=q->next; { int i, j = 0 ; /**********found**********/ for(i = 1 ; i <= x ; i +=2 ) free(___1___); /**************found**************/ /**********found**********/ if((x % i) == 0) pp[j++] = ___1___ ; q=p->___2___; } /**************found**************/ else *n = ___2___ ;} { p=q; main(){ int x, aa[1000], n, i ; /**********found**********/

printf( \ q=q->___3___; } } }} scanf(\SLIST *creatlist(int *a) /**************found**************/ { SLIST *h,*p,*q; int i; fun(x, ___3___ ) ; h=p=(SLIST *)malloc(sizeof(SLIST)); for( i = 0 ; i < n ; i++ ) for(i=0; idata=a[i]; p->next=q; p=q; } 第一空: i 第二空: j 第三空:aa,&n

11

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

case 3: c3++; }

n /= 10;}}

main(){ long n=123114350L;

fun(n); printf(\printf(\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**********/

47.给定程序的功能是实现矩阵(3行3列)的转置。 return ch +'a'-___2___ ; #include /**********found**********/ int fun(int array[3][3]) return ___3___;} { int i,j,arr[3][3] ; main(){ char c1, c2; memcpy(arr, array, 9*sizeof(int)) ; printf(\ for(i = 0 ; i < 3 ; i++) c1='w'; c2 = fun(c1); for(j = 0 ; j < 3 ; j++) printf(\/**************found**************/ c1='W'; c2 = fun(c1); array[i][j] = ___1___ ;} printf(\main(){ int i,j; c1='8'; c2 = fun(c1); int array[3][3]={{100,200,300}, printf(\ {400,500,600}, 第一空:&& 第二空:’A’ 第三空:ch {700,800,900}};

50.给定程序的功能是对指定字符在字符串a中出现的 for (i=0;i<3;i++)

次数进行统计,统计的数据存到b数组中。其中:字 { for (j=0;j<3;j++)

符’Z’ 出现的次数存放到b[0]中,字符’Y’出现的次 printf(\

数存放到b[1],字符’X’出现的次数存放到b[2]中,字 printf(\

符’W’出现的次数存放到b[3],字符’V’出现的次数/**************found**************/

存放到b[4]中,其它字符出现的次数存到b[5]中。 fun(___2___);

#include printf(\

#include for (i=0;i<3;i++)

void fun(char *a, int b[]) { for (j=0;j<3;j++)

{ int i; /**************found**************/

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

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

第一空:arr[j][i] 第二空:array 第三空:array[i][j] for (i=0; i< ___1___(a); i++)

if (a[i] >= 'V' && a[i] <= 'Z')

48.函数fun的功能是:统计长整数n的各个位上出现 b[4-(a[i]-'V')]++;

数字1、2、3的次数,并通过上部(全局)变量 c1、c2、/**************found**************/ c3返回主函数。例如:当n=123114350时,结果应该是: ___2___ b[5]++;} c1=3 c2=1 c3=2。 main() #include { int i, b[6]; int c1,c2,c3; char a[100] = \void fun(long n) /**************found**************/ { c1 = c2 = c3 = 0; fun(___3___); while (n) { printf(\/**********found**********/ for (i=0; i<6; i++) printf(\ switch(___1___){ printf(\/**********found**********/ 第一空:strlen 第二空:else 第三空:a,b case 1: c1++;___2___;

50.函数fun的功能是:将形参a所指数组中的前半部/**********found**********/

分元素中的值和后半部分元素中的值对换。形参n中存 case 2: c2++;___3___;

12

放数组中的数据的个数,若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(\ for (i=0; i

printf(\ for (i=0; i

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

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************/

52.给定程序的功能是把s串中所有的字符前移一个位 return ___2___;} 置,串中的第一个字符移到最后。例如:s串中原有的字getindex( int n ) 符串为:Mn.123xyZ,则调用函数后,s串中的内容为:{ int i; n.123xyZM /************found************/ #include ___3___ #define N 81 { printf(\fun ( char *s ) scanf (\{ char b[N] ; } while( i < 0 || i > n-1 ); sprintf(b, \ return i;} /**************found**************/ main( ) strcpy(___1___) ;} { int n, d, main( ) a[NUM]={21,22,23,24,25,26,27,28,29,30}; { char a[ N ] ; n = NUM;

printf ( \printf (\ printf ( \original string is : \); puts( a ); arrout ( a, n ); /**************found**************/ d = getindex( n ); n = arrdel ( a, n, d ); fun ( ___2___ ); printf (\the data after delete :\\n\ printf ( \arrout( a, n );} /**************found**************/ 第一空:m 第二空:n 第三空: do ___3___ ( a );}

55.给定程序的功能是从字符串s尾部开始,按逆序把第一空:s,b 第二空:a 第三空:puts

在其中出现的每相邻的两个字符,紧随其后重复出现一

53.给定程序的功能是计算并输出high以内最大的10次,放在一个新串t中,若字符串s中头部有剩余的单个素数和。high由主函数传给fun函数。例如:high值个字符也重复,放在t的最后。例如:当s中的字符串为100,函数的值为732。 为:”12345”时,则t中的字符串应该#include 为:”5454323211” #include #include int fun( int high ) #include { int sum = 0, n=0, j, yes; void fun (char *s, char *t) /************found************/ { int i, j, sl; while ((high >= 2) ___1___ (n < 10)) sl = strlen(s); { yes = 1; for(i=sl-1,j=0;i>=0;i-=2) for (j=2; j<=high/2; j++ ) { t[j++] = s[i];

13

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(\enter string s:\scanf(\s);

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

printf(\第一空:s[i] 第二空:>= 第三空:s,t

even=fun(head);

printf(\ outresult(even, stdout);}

第一空:NODE 第二空:h->next 第三空:p->next

57.给定程序的功能是把在字符串s中出现的每个字符,

紧随其后重复出现一次,形成一个新串放在t中,且在t中把原相邻字符的位置进行了互换。例如:当s中的字符串为:”12345”时,则t中的字符串应该为:”2211443355”。 #include #include

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

/************found************/ sl = ___1___(s);

for (i=0, j=0; i

{ t[2*j] = s[i+1]; t[2*j +1] = s[i+1];

j++; }

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

{ char s[100], t[100]; printf(\enter string s:\scanf(\s);

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

printf(\第一空:strlen 第二空:j=j+1 第三空: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 ,\ while(p)

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

{fprintf(pf,\sum of even numbers: %d\\n\

main(){ NODE *head; int even; head=creatlink(12); head->data=9000;

outlink(head , stdout);

14

58.给定程序的功能是根据公式求P的值,结果由函数值m!带回。m与n为两个正整数且要求m>n。P?

n!(m?n)!例如:m=11,n=4时,运行结果为330.000000。

#include long jc(int m)

{ long s=1; int i ;

/**************found**************/ for(i=1;i<=m;i++) s=___1___ ; return s;}

float fun(int m, int n) { float p;

/**************found**************/ p=1.0*jc(m)/jc(n)/jc(___2___) ; /**************found**************/ ___3___;}

main(){ printf(\第一空:s*i 第二空:m-n 第三空:return p

59.给定程序的功能是把a数组中的n个数,和b数组中

逆序的n个数一一对应相乘求平方,结果存在c数组中。例如:当a数组中的值是:1、3、5、7、8,b数组中的值是:2、3、4、5、8,c中存放的数据是:64、225、400、441、256。

#include

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

for (i=0; i

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

_1___ = (a[i] * b[n-1-i]) *(a[i] * b[n-1-i]);} main()

{ int i, a[100]={1,3,5,7,8}, b[100]={2,3,4,5,8}, c[100];

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

printf(\

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

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

第一空:c[i] 第二空:a,b,c 第三空:c[i]

60.给定程序的功能是根据公式计算S,计算结果通过形

参指针sn传回;n通过形参传入。

11111Sn???????例如,若n的值为15

13572n?1时,输出结果是:S=0.769788 N=15。 #include

void fun(float *sn, int n)

{/**************found**************/ int i,j=___1___; float s=0.0;

for(i=0;i<=n;i++) { s=s+j*1.0/(2*i+1); j*=-1; }

/**************found**************/ ___2___=s;}

main(){ int n=15; float s;

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

printf(\第一空:1 第二空:*sn 第三空:&s,n

1 2 3 程序执行结果为 0 0 1 4 5 6 0 0 4 7 8 9 0 0 7 #include #define N 4

void fun(int (*t)[N], int m) { int i, j;

/**********found**********/ for(i=0; i=0; j--) /**********found**********/

t[i][j+___2___ ]=t[i][j]; /**********found**********/ for(j=0; j<___3___; j++) t[i][j]=0; }} main()

{ int t[][N]={21,12,13,24,25,16,47,

38,29,11,32,54,42,21,33,10}, i, j, m; printf(\ for(i=0; i

printf(\ printf(\

printf(\scanf(\ fun(t,m);

printf(\ for(i=0; i

printf(\ printf(\

第一空:i++ 第二空:m 第三空:m

61.给定程序的功能是把s 串中所有的字母改写该字母

63.给定程序的功能是建立一个带有头结点的单向链

表,并用随机函数为各结点赋值。函数fun的功能查找结点数据域最大值,并且作为函数值返回。 #include #include typedef struct aa

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

/***********found**********/ ___1___ *p; p=h->next;

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

{ if(p->data>max) max=p->data;

/***********found**********/ ___3___ } return max;}

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

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

62.给定程序中,函数fun的功能是:有N×N矩阵,根 { s=(NODE *)malloc(sizeof(NODE)); 据给定的m(mdata=rand();

s->next=p->next; 左边置为0。例如,N=3,m=2,则下列矩阵

的下一个字母,字母z改写成字母a。大写字母仍为大写

字母,小写字母仍为小写字母,其它字符不变。 #include #include #include #define N 81 fun ( char *s )

{/**************found**************/ char *p = ___1___ ; while(*p) {

/**************found**************/ if(*p == 'Z') *p = ___2___ ; /**************found**************/ else if(*p == 'z') *p = ___3___ ; else if(isalpha(*p)) *p = (*p) + 1 ; p++ ; }}

main( ){ char a[N];

printf ( \ printf ( \original string is : \); puts( a ); fun ( a );

printf ( \ puts ( a );}

第一空:s 第二空:’A’或65 第三空:’a’或97

15


程序填空题(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:八年级上册思品复习主要知识点(精品)

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

马上注册会员

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