填空题(C语言) 联系客服

发布时间 : 星期三 文章填空题(C语言)更新完毕开始阅读

填空题(C) 17

出现的次数存放到b[O]中,字符‘y’出现的次数存放到b[1]中,字符‘x’出现的次数存放到b[2]中,字符‘w’ main()

出现的次数存放到b[3]中,字符‘v’出现的次数存放到b[4]中,其它字符出现的次数存到b[5]中。例如,当a中的字符串为:“yyzxxwly+wvp”,调用该函数后。b中存放数据应是:1、3、2、2、1、3。 #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++)

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

if (a[i] >= 'v' ___2___ a[i] <= 'z') b[4 - (a[i] - 'v')]++; /**************found**************/ ___3___ b[5]++; }

main()

{ int i, b[6]; char a[100] = \ fun(a, b);

printf(\

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

答案:【1】strlen 【2】&& 【3】else

48.给定程序的功能是根据公式计算s,计算结果通过形参指针sn传回;n通过形参传入。 S11n?11?3?15?7?...1

2n?1 例如:若n的值为15时,输出的结果是:s=O.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; }

{ int n=15; float s;

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

printf(\}

答案:【1】1 【2】*sn 【3】&s, n

49.给定程序的功能是把s串中所有的字母改写成该字母的下一个字母,字母z改写成字母a。大写字母仍为大写字母,小写字母仍为小写字母,其它的字符不变。例如:s串中原有的字符串为;Mn.123Zxy,则调用该函数后,s串中的内容为:N0.123Ayz。 #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 ); }

答案:【1】s 【2】'A' 【3】'a'

50.给定程序中,函数fun的功能是:有N×N矩阵,根据给定的m(如m<=N)值,将每行元素中的值均右移m个位置,左边置为0。例如,N=3,m=2,有下列矩阵 1 2 3 4 5 6 7 8 9 程序执行结呆为

填空题(C) 18

O 0 l 0 0 4 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(\

fun(t,m);

printf(\ for(i=0; i

printf(\ printf(\ } } 答案:【1】i++ 【2】m 【3】m

51.给定程序中,函数fun的功能是:在带有头结点的单向链表中,查找数据域中值为ch的结点。找到后通过函数值返回该结点在链表中所处的顺序号;若不存在值为ch的结点,函数返回O值。 #include #include #define N 8 typedef struct list { int data;

struct list *next; } SLIST;

SLIST *creatlist(char *); void outlist(SLIST *);

int fun( SLIST *h, char ch) { SLIST *p; int n=0; p=h->next;

/**********found**********/ while(p!=___1___) { n++;

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

if (p->data==ch) return ___2___; else p=p->next; }

return 0; }

main()

{ SLIST *head; int k; char ch;

char a[N]={'m','p','g','a','w','x','r','d'}; head=creatlist(a); outlist(head);

printf(\ scanf(\

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

if (k==0) printf(\

else printf(\ }

SLIST *creatlist(char *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(\list is NULL!\\n\ else

{ printf(\ do

{ printf(\ while(p!=NULL); printf(\ } } 答案:【1】0 【2】h 【3】head,ch

填空题(C) 19

52.给定程序中,函数fun的功能是:统计出带有头结点的单向链表中结点的个数,存放在形参n所指的 do

{ printf(\存储单元中。

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

struct list *next; } SLIST;

SLIST *creatlist(int *a); void outlist(SLIST *);

void fun( SLIST *h, int *n) { SLIST *p;

/**********found**********/ ___1___=0; p=h->next; while(p) { (*n)++;

/**********found**********/ p=p->___2___; } }

main()

{ SLIST *head;

int a[N]={12,87,45,32,91,16,20,48}, num; head=creatlist(a); outlist(head); /**********found**********/ fun(___3___, &num);

printf(\}

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(\

while(p!=NULL); printf(\ } } 答案:【1】(*n) 【2】next 【3】head

53.给定程序中,函数fun的功能是:计算出带有头结点的单向链表中各结点数据域之和作为函数值返回。 #include #include #define N 8 typedef struct list { int data;

struct list *next; } SLIST;

SLIST *creatlist(int *); void outlist(SLIST *); int fun( SLIST *h)

{ SLIST *p; int s=0; p=h->next; while(p) {

/**********found**********/ s+= p->___1___;

/**********found**********/ p=p->___2___; }

return s; }

main()

{ SLIST *head;

int a[N]={12,87,45,32,91,16,20,48}; head=creatlist(a); outlist(head); /**********found**********/

printf(\}

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; }

填空题(C) 20

void outlist(SLIST *h)

{ SLIST *p; p=h->next; if (p==NULL) printf(\

else { printf(\ do { printf(\ while(p!=NULL); printf(\ } } 答案:【1】data 【2】next 【3】head 54.人员的记录由编号和出生年、月、日组成,N名人员的数据己在主函数中存入结构体数组std中,且编号唯一。函数fun的功能是:找出指定编号人员的数据,作为函数值返回,由主函数输出,若指定编号不存在,返回数据中的编号为空串。 #include #include #define N 8 typedef struct { char num[10]; int year,month,day ; }STU; /**********found**********/ ___1___ fun(STU *std, char *num) { int i; STU a={\ for (i=0; i

if( strcmp(___2___,num)==0 ) /**********found**********/ return (___3___);

return a; } main() { STU std[N]={ {\

{\{\{\

{\

STU p; char n[10]=\

p=fun(std,n);

if(p.num[0]==0)

printf(\

else

{ printf(\

printf(\ } }

答案:【1】STU 【2】std[i].num 【3】std[i] 55.人员的记录由编号和出生年、月、日组成,N名人员的数据己在主函数中存入结构体数组std中。函数fun的功能是;找出指定出生年份的人员,将其数据放在形参k所指的数组中,由主函数输出,同时由函数值返回满足指定条件的人数。 #include #define N 8 typedef struct { int num; int year,month,day ; }STU; int fun(STU *std, STU *k, int year) { int i,n=0; for (i=0; i

printf(\ n=fun(std,k,year); if(n==0)

printf(\ else { printf(\ for(i=0; i

printf(\ } }

答案:【1】std[i].year 【2】std[i] 【3】n 56.给定程序通过定义并赋初值的方式,利用结构体变量存储了一名学生的学号、姓名和3门课的成绩。函数fun的功能是将该学生的各科成绩都乘以一个系数a。 #include typedef struct { int num; char name[9];