Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:定义结构型数组输入输出学生成绩问题

Posted by 484117 at 2012-10-16 13:21:33
In Reply To:定义结构型数组输入输出学生成绩问题 Posted by:484117 at 2012-10-16 13:15:16
/*定义一个结构体数组,存放N个学生的成绩,每位学生的成绩是一个结构体类型的数据
其成员分别为:学号 姓名 3门成绩与总分 
目的:从键盘输入每位同学的学号 姓名 成绩 然后计算出总分 在屏幕上输出每位同学的学号 姓名 成绩以及总分 
要求使用自定义函数 并且用结构体指针作为函数的形参来实现
time:   2012-10-16   
editor: saozi*/

#include<stdio.h>
#define N 3

struct student
{
	int number;
	char name[10];
	float math;
	float chinese;
	float english;
	float total; 
};
struct student stu[N];

float sumGrade(struct student *q);

void main()
{
	int i;
	for(i=0;i<N;i++)
	{
		printf("please input the relative Ifo of number %d :",(i+1));
		scanf("%d,%s,%f,%f,%f\n",&(stu[i].number),&(stu[i].name),&(stu[i].chinese),&(stu[i].math),&(stu[i].english));
	}
	struct student *m=stu;
	for(i=0;i<N;i++)
	{
		float last=1.0;
		printf("output the relative Ifo of number %d :",(i+1));
		printf("%d,%s,%f,%f,%f",m->number,m->name,m->chinese,m->english,m->math);
		/*last=sumGrade(m);
		printf("%f\n",last);*/
		m++;
	}
}


float sumGrade(struct student *q)
{
	q->total=(q->chinese)+(q->english)+(q->math);
	return (q->total);
}

求总分的函数为0

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator