zoukankan      html  css  js  c++  java
  • 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
    ");
    		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!
    ");
    
    	return 0;
    }
    void new_student (struct student students[])
    {
    	struct student s;
    	if(Count==MaxSize)
    	{
    		printf("The array is full!
    ");
    		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!
    ");
    		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
    ",students[i].average);
    		}
    		else
    			printf("Not Found!");
    }
    void output_student(struct student students[])
    {
    	int i;
    	if(Count==0){
    		printf("Count of students is zero!
    ");
    		return;
    	}
    	printf("num	 name	 math	 english	 computer	 average
    ");
    	for(i=0;i<Count;i++)
    	{
    		printf("%d	",students[i].num);
    		printf("%s	",students[i].name);
    		printf("%d	",students[i].math);
    		printf("%d	",students[i].english);
    		printf("%d	",students[i].computer);
    		printf("%.2Lf
    ",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
    ");
    		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!
    ");
    
    	return 0;
    }
    void new_student (struct student students[])
    {
    	struct student s;
    	if(Count==MaxSize)
    	{
    		printf("The array is full!
    ");
    		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!
    ");
    		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
    ",students[i].average);
    		}
    		else
    			printf("Not Found!");
    }
    void output_student(struct student students[])
    {
    	int i;
    	if(Count==0){
    		printf("Count of students is zero!
    ");
    		return;
    	}
    	printf("num	 name	 math	 english	 computer	 average
    ");
    	for(i=0;i<Count;i++)
    	{
    		printf("%d	",students[i].num);
    		printf("%s	",students[i].name);
    		printf("%d	",students[i].math);
    		printf("%d	",students[i].english);
    		printf("%d	",students[i].computer);
    		printf("%.2Lf
    ",students[i].average);
    	}
    }
    

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

  • 相关阅读:
    [javascript] vuejs为输入框增加回车事件
    iview上的兼容性问题
    python+vscode安装与插件配置
    Chrome浏览器获取XPATH的方法----通过开发者工具获取
    使用谷歌浏览器定位xpath是否准确
    [PHP] xpath提取网页数据内容
    PHP中preg_match正则匹配的/u /i /s是什么意思
    Flink connect 算子实践
    DataStreamUtils 连续keyBy 优化
    Heartbeat原理及部署
  • 原文地址:https://www.cnblogs.com/lxhlxx900126/p/3434490.html
Copyright © 2011-2022 走看看