相关题目
下面程序的功能是计算1至10之间的奇数之和及偶数之和。 请选择填空。
# include
main ( )
{ int a,b,c,i;
a=c=0;
for(i=0;i<=10;i+=2)
{ a+=i;
[ ];
c+=b;
}
printf(“偶数之和=%d\n ”,a) ;
下面程序的运行结果是( )。
#include
main()
{ int i;
for(i=1;i<=5;i++)
switch(i%5)
{case 0: printf(“*”);break;
case 1: printf(“#”);break;
default: printf(“\\n”);
case 2: printf(“&”);
}
}
下面程序的运行结果是( )。
#include
main()
{int i,b,k=0;
for(i=1;i<=5;i++)
{b=i%2;
while(b-->0) k++;
}
printf ("%d,%d",k,b);
}
选出使变量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;
}
