相关题目
选出使变量i的运行结果为4的表达式( )。
当运行以下程序时 , 从键盘输入My BooK (
# include
char fun(char *s)
{
if(*s='A')*s+=32;return *s;
}
main ( )
{ char c[80],*p;
p=c;
scanf("%s",p);
while(*p){*p=fun(p);putchar(*p);p++;}
printf("\\n");
}
下面的程序是计算一组学生的平均成绩和不及格人数,请根据题目要求填空。
include "stdio.h"
struct student
{
t id;
har name[20];
char sex;
float score;}stu1[5]=
{
{101,"Li ping",'M',45},
{102,"Zhang ping",'M',62.5},
{103,"He fang",'F',92.5},
{104,"Cheng ling",'F',87},
{105,"Wang ming",'M',58},
};
main()
{
struct student *ps;
void ave(struct student *ps);
_____【1】_________________;
ave(ps);
}
void ave(struct student *ps)
{
int c=0,i;
float ave,s=0;
for(i=0;i<5;_____【2】_____________)
{
s+=ps->score;
if(ps->score<60) _____【3】_____________;
}
printf("s=%f\n",s);
_____【4】_____________;
printf("average=%f\ncount=%d\n",ave,c);
}
下面的程序输入4名学生的学号、姓名和成绩,然后输出成绩最高的学生的学号、姓名和成绩。将程序补充完整。
#include "stdio.h"
main()
{
struct student
{
int id;
char name[20];
float score;
};
struct student stu[4];
_____【1】_____________;
int i,temp=0;
float max;
for(i=0;i<4;i++)
scanf("%d%s%f",____【2】_________,&stu[i].name,&stu[i].score);
for(max=stu[0].score,i=1;i<4;i++)
if(____【3】_________)
{max=stu[i].score;temp=i;}
____【4】_________;
printf("\nThe maximum score:\n");
printf("No.:%d\nname:%s\nscore:%4.1f\n",p->id,p->name,p->score);
}
设有若干个人员的数据,其中有学生和教师。学生的数据中包括:姓名、号码、性别、职业、班级。教师的数据包括:姓名、号码、性别、职业、职务。现要求把它们放在同一表格中。请填空完成程序。
#include
struct
{ int num;
char name[10];
char sex;
char job;
_______【1】________
{ int banji;
char position[10];
} category;
} person[2];
void main( )
{ int n,i;
for(i=0;i<2;i++)
{ scanf(“%d,%s,%c,%c”,&person[i].num,&person[i].name,&person[i].sex,_______【2】_________);
if(person[i].job==‘s’) scanf(“%d”,&person[i].category.banji);
else if(person[i].job==‘t’) scanf(“%s”,&person[i].category.position);
else printf(“input error”);
}
printf(“\n”);
printf(“No. Name sex job class/position\n”);
for(i=0;i<2;i++)
{ if(_______【3】__________)
printf(“%-6d %-10s %-3c %-3c %-6d\n”,person[i].num,person[i].name,
person[i].sex, person[i].job, person[i].category.banji);
else
printf(“%-6d %-10s %-3c %-3c %-6s\n”,person[i].num,person[i].name,
person[i].sex, person[i].job, ________【4】____________);
}
}
下面的代码实现将一个节点插入到链表中,其中结构体名称为student,请填空。
struct student *insert(______【1】_______, struct student *stud)
{ struct student *p0, *p1, *p2;
p1=head;
p0=stud;
if(head==NULL) {head=p0;______【2】________; break;}
while(p1!=NULL)
{
if (p0->numnum) break;
________【3】___________;
p1=p1->next;
}
if (p1==head) head=p0;
else p2->next=p0;
p0->next=p1;
______【4】_________;
return(head);
}
下面的代码实现建立一个有若干名学生数据的单向动态链表,请填空。
#include
#include
#define LEN sizeof(struct student)
struct student
{ long num;
float score;
struct student * next;
};
int n;
struct student *creat();
void print(struct student * p);
main()
{
struct student *head;
________【1】__________;
display(head);
}
void print(struct student * p)
{
while(p)
{ printf("%ld\t%f\n",p->num, p->score);
_______【2】________; }
}
struct student *creat()
{
struct student *p1,*p2,*head;
long sno;
float score;
p1=p2=head=NULL;
______【3】_________;
while(1)
{ scanf("%ld,%f",&sno,&score);
if(sno==0) break;
n++;
p1=(struct student*)malloc(LEN);
p1->num=sno;
p1->score=score;
if(head==NULL)
head=p1;
else
_________【4】____________;
p2=p1;
}
if(p2) p2->next=NULL;
return head;
}
下面的函数实现删除动态链表中指定的结点,以学号num作为删除结点的标志(查找对象)。请填空。
struct student *del(struct student *head,long num)
{ struct student *p1,*p2;
if(______【1】_______) {printf(“\\n list null ! \\n”); return(head); }
p1=head;
while(num !=p1->num && p1->next != NULL)
{ _____【2】______; p1=p1->next; }
if(num == p1->num)
{ if(p1 = = head) head=p1->next;
else __________【3】____________;
printf(“delete: %d\\n”,num);
n=n-1;
________【4】_________;
}
else printf(“%ld not been found ! \\n”,num);
return(head);
}
___________【1】_______________
#include
void main()
{ int s;
float n,t,pi;
t=1; pi=0; n=1.0; s=1;
while((______【2】________)
{ pi=pi+t;
n=n+2;
s= -s;
_____【3】_______;
}
_______【4】________;
printf("pi=%10.6f\n",pi);
}
求100~200间的全部素数。
#include
________【1】__________
void main()
{ int m, k, i, n=0;
for(m=101;______【2】_______;m=m+2)
{ k=sqrt(m);
for(i=2;i<=k;i++)
if(m%i==0) ______【3】_______;
if(i>k) {printf("%d",m);______【4】________;}
if(n%10==0) printf("\n");
}
printf("\n");
}
