9-1

#include<stdio.h>
#define MaxSize 50
struct student
{
	int num;
	char name[10];
	int computer,english,math;
	double average;
};
int Count = 0;
void new_student(struct student students[]);
void search_student(struct student students[],int num);
void output_student(struct student students[]);
int mian(void)
{
int choice,num;
	struct student students[MaxSize];
	do
	{
		printf("choice: 1:new 2:search 3:output 0:exit\n");
		scanf("%d",&choice);
		switch(choice)
		{
		case 1: new_student(students);  break;
		case 2: printf("Please input the students's number:");
			    scanf("%d",&num);
				search_student(students,num);
				break;
		case 3: output_student(students);  break;
		case 0: break;
		}
	}
	while(choice!=0);
	printf("END!\n");

	return 0;
}
void new_student (struct student students[])
{
	struct student s;
	if(Count==MaxSize)
	{
		printf("The array is full!\n");
		return;
	}
	printf("Input the student's num:");
	scanf("%d",&s.num);
	printf("Input the student's name:");
	scanf("%s",s.name);
	printf("Input the student's math score:");
	scanf("%d",&s.math);
	printf("Input the student's english score:");
	scanf("%d",&s.english);
	printf("Input the student's computer score:");
	scanf("%d",&s.computer);
	s.average=(s.math+s.english+s.computer)/3.0;
	students[Count]=s;
	Count++;
}
void search_student(struct student students[],int num)
{
	int i,flag=0;
	if(Count==0)
	{
		printf("Count of students is zrero!\n");
		return;
	}
	for(i=0;i<Count;i++)
		if(students[i].num==num)
		{
			flag=1;
			break;
		}
		if(flag)
		{
			printf("num:%d,",students[i].num);
			printf("name:%s,",students[i].name);
			printf("math:%d,",students[i].math);
			printf("english:%d,",students[i].english);
			printf("computer:%d,",students[i].computer);
			printf("average:%.2Lf\n",students[i].average);
		}
		else
			printf("Not Found!");
}
void output_student(struct student students[])
{
	int i;
	if(Count==0){
		printf("Count of students is zero!\n");
		return;
	}
	printf("num\t name\t math\t english\t computer\t average\n");
	for(i=0;i<Count;i++)
	{
		printf("%d\t",students[i].num);
		printf("%s\t",students[i].name);
		printf("%d\t",students[i].math);
		printf("%d\t",students[i].english);
		printf("%d\t",students[i].computer);
		printf("%.2Lf\n",students[i].average);
	}
}

对于这个代码我已经无话可说了
我花了一个小时打好了。。花了不止一个小时在那里找错误。。。。到现在还有两个   我已经崩溃了。。。

老师你就原谅我了把  我眼珠子都要弹出来了

 

#include<stdio.h>
#define MaxSize 50
struct student
{
	int num;
	char name[10];
	int computer,english,math;
	double average;
};
int Count = 0;
void new_student(struct student students[]);
void search_student(struct student students[],int num);
void output_student(struct student students[]);
int main(void)
{
int choice,num;
	struct student students[MaxSize];
	do
	{
		printf("choice: 1:new 2:search 3:output 0:exit\n");
		scanf("%d",&choice);
		switch(choice)
		{
		case 1: new_student(students);  break;
		case 2: printf("Please input the students's number:");
			    scanf("%d",&num);
				search_student(students,num);
				break;
		case 3: output_student(students);  break;
		case 0: break;
		}
	}
	while(choice!=0);
	printf("END!\n");

	return 0;
}
void new_student (struct student students[])
{
	struct student s;
	if(Count==MaxSize)
	{
		printf("The array is full!\n");
		return;
	}
	printf("Input the student's num:");
	scanf("%d",&s.num);
	printf("Input the student's name:");
	scanf("%s",s.name);
	printf("Input the student's math score:");
	scanf("%d",&s.math);
	printf("Input the student's english score:");
	scanf("%d",&s.english);
	printf("Input the student's computer score:");
	scanf("%d",&s.computer);
	s.average=(s.math+s.english+s.computer)/3.0;
	students[Count]=s;
	Count++;
}
void search_student(struct student students[],int num)
{
	int i,flag=0;
	if(Count==0)
	{
		printf("Count of students is zrero!\n");
		return;
	}
	for(i=0;i<Count;i++)
		if(students[i].num==num)
		{
			flag=1;
			break;
		}
		if(flag)
		{
			printf("num:%d,",students[i].num);
			printf("name:%s,",students[i].name);
			printf("math:%d,",students[i].math);
			printf("english:%d,",students[i].english);
			printf("computer:%d,",students[i].computer);
			printf("average:%.2Lf\n",students[i].average);
		}
		else
			printf("Not Found!");
}
void output_student(struct student students[])
{
	int i;
	if(Count==0){
		printf("Count of students is zero!\n");
		return;
	}
	printf("num\t name\t math\t english\t computer\t average\n");
	for(i=0;i<Count;i++)
	{
		printf("%d\t",students[i].num);
		printf("%s\t",students[i].name);
		printf("%d\t",students[i].math);
		printf("%d\t",students[i].english);
		printf("%d\t",students[i].computer);
		printf("%.2Lf\n",students[i].average);
	}
}

 谢谢老师的改错  我终于对了。。。。

转载于:https://www.cnblogs.com/lxhlxx900126/p/3434490.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值