第一范文网 - 专业文章范例文档资料分享平台

C语言程序填空题

来源:用户分享 时间:2025/5/31 16:01:47 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

printf(\,s3); }

【3.42】已知某数列前两项为2和3,其后继项根据前面最后两项的乘积,按下列规则生成:

① 若乘积为一位数,则该乘积即为数列的后继项;

② 若乘积为二位数,则该乘积的十位上的数字和个位上的数字依次作为数列的两个后继项。

下面的程序输出该数列的前N项及它们的和,其中,函数sum(n,pa) 返回数列的前N项和,并将生成的前N项存入首指针为pa的数组中,程序中规定输入的N值必须大于2,且不超过给定的常数值MAXNUM。 例如:若输入N的值为10,则程序输出如下内容: sum(10)=44 2 3 6 1 8 8 6 4 2 4 #include \#define MAXNUM 100 int sum(n, pa) int n, *pa;

{ int count, total, temp; *pa = 2; ① =3; total=5; count=2;

while( count++

} else

{ ② = temp/10; total += *pa; if( count

{ count ++; pa++; ③ = temp; total += *pa; } } } ④ ; } main()

{ int n, *p, *q, num[MAXNUM]; do

{ printf(\; scanf(\; }while( ⑤ );

printf(\; for( p=num, q = ⑥ ; p

【3.43】下面程序的功能是输入学生的姓名和成绩,

然后输出。

#include struct stuinf

{ char name[20]; /* 学生姓名 */ int score; /* 学生成绩 */ } stu, *p; main ( ) { p=&stu;

printf(\; gets( ① );

printf(\; scanf(\, ② );

printf(\, ③ , ④ ); }

【3.44】下面程序的功能是按学生的姓名查询其成绩排名和平均成绩。查询时可连续进行,直到输入0时才结束。

?? #include #include #define NUM 4 ? struct student ? { int rank; char *name; float score; ????????};

???????? ① stu[ ]={ 3,\,89.3, ???????? 4,\,78.2, ???????? 1,\,95.1,

???????? 2,\,90.6 };

????????main()

????????{ char str[10]; ???????? int i; ???????? do

{ printf(\; ???????? scanf(\,str); ???????? for( i=0;i

???????? { printf(\,stu[i].name); ???????? printf(\,stu[i].rank); ???????? printf(\,stu[i].score);???????? ③ ; ???????? }

???????? if( i>=NUM ) printf(\; ???????? }while( strcmp(str,\; ????????}

【3.45】下面程序的功能是从终端上输入5个人的年龄、性别和姓名,然后输出。 #include \struct man { char name[20]; unsigned age; char sex[7]; };

main ( )

{ struct man person[5]; data_in(person,5); data_out(person,5); }

data_in(struct man *p, int n )

{ struct man *q = ① ;

for( ;p

{ printf( \;

scanf(\p->sex); ② ; } }

data_out( struct man *p, int n )

{ struct man *q = __③__; for( ;p

printf(\;%u;%s\\n\p->name, p->age, p->sex); }

【3.46】输入N个整数,储存输入的数及对应的序号,并将输入的数按从小到大的顺序进行排列。要求:当两个整数相等时,整数的排列顺序由输入的先后次序决定。例如:输入的第3个整数为5,第7个整数也为5,则将先输入的整数5排在后输入的整数5的前面。程序如下:

#include \

#define N 10

struct { int no; int num; } array[N]; main( )

{ int i,j,num; for( i=0;i

{ printf(\,i);

scanf(\,&num);

for( ① ;j>=0&&array[j].num ② num; ③ )

array[j+1]=array[j]; array[ ④ ].num=num; array[ ⑤ ].no=i; }

for( i=0;i

printf(\,%d\\n\,i,array[i].num,array[i].no); }

【3.47】以下程序的功能是:读入一行字符(如:a、...y、z),按输入时的逆序建立一个链接式的结点序列,即先输入的位于链表尾(如下图),然后再按输入的相反顺序输出,并释放全部结点。

#include main( ) { struct node

{ char info;

struct node *link; } *top,*p; char c; top=NULL;

while((c= getchar( )) ① )

{ p=(struct node *)malloc(sizeof(struct node)); p->info=c;

p->link=top;

top=p;

}

while( top )

{ ② ;

top=top->link;

putchar(p->info);

free(p);

}

}

【3.48】下面函数将指针p2所指向的线性链表,串接到p1所指向的链表的末端。假定p1所指向的链表非空。

#define NULL 0

struct link

{ float a;

struct link *next;

};

concatenate ( p1,p2 )

struct list *p1,*p2;

{ if( p1->next==NULL ) p1->next=p2; else

concatenate( ① ,p2); }

【3.49】下面程序的功能是从键盘输入一个字符串,然后反序输出输入的字符串。 #include

struct node

{ char data;

struct node *link;

}*head;

main()

{ char ch;

struct node *p;

head = NULL;

while(( ch=getchar())!='\\n' )

{ p = (struct node *)malloc(sizeof(struct node));

p->data = ch; p->link = ① ;

head = ② ;

}

③ ;

while( p!=NULL )

{ printf(\;

p = p->link;

搜索更多关于: C语言程序填空题 的文档
C语言程序填空题.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c0hu3t0g55l1cf865breu5a66i6tmb7010rx_4.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top