c语言输出 成绩单

输入4名学生的姓名及三门课成绩,打印学生成绩表。(姓名、三门课成绩、平均分)。试编写一个程序,包括主函数和如下子函数:
(1)输入每个学生的姓名及三门课成绩。
(2)计算每个学生的平均分。
(3)输出每个学生的姓名、三门课成绩及平均分。
并将输入的测试数据和运行结果写入实验报告。
提示:input函数完成每个学生的姓名及三门课成绩的录入。average函数计算每个学生的平均分,output函数输出每个学生的姓名、三门课成绩及平均分。

第1个回答  2008-10-31
#include<stdlib.h>

typedef struct
{
char name[30];
double score[3];
}Table;

void Input( Table *t )
{
if (t!=NULL)
{
printf("Input the student's name:\n");
scanf("%s",t->name);
printf("Input the student's scores, from subject 1 to 3:\n");
scanf("%lf %lf %lf", &(t->score[0]), &(t->score[1]), &(t->score[2]) );
}
}

void Output( Table t[] )
{
double average( double s[]);
int i;
if (t!=NULL)
{

printf("\nName\tS1\tS2\tS3\tAve\n\n");

for(i=0; i<4; i++)
{
printf("%s\t%3.1f\t%3.1f\t%3.1f\t%4.2f\n", t[i].name, t[i].score[0],
t[i].score[1], t[i].score[2], average(t[i].score));
}
}
}

double average( double s[] )
{
int i;
double sum=0.0;
for(i=0; i<3; i++)
{
sum += s[i];
}

return sum/(double)i;
}

main()
{
Table table[4];
int i;

for(i=0; i<4; i++)
{
Input(table+i);
}
printf("-----------\n");

Output(table);

}

想不到这么麻烦。本回答被网友采纳
第2个回答  2008-10-31
试一下这个
我弄了好久的啊!!

#include<stdio.h>
void input(char name[],float a[3][4] );
void average(float a[3][4]);
void output(char name[],float a[3][4] );
void main()
{
char name[10];
float a[3][4];
input(name,a);
average(a);
output(name,a);
}

void input(char name[],float a[3][4] )
{
int i;
for(i=0;i<3;i++)
{
printf("Plese enter the %dst name:\n",i+1);
scanf("%s",name);
printf("\nPlese enter the %dst fengsu,and used , \n",i+1);
scanf("%f,%f,%f",a[0],a[1],a[2]);
}
}

void average(float a[3][4])
{
int i;
for(i=0;i<3;i++)
{
a[i][3]=a[i][0]+a[i][1]+a[i][2];
a[i][3]=a[i][3]/3.0;
}
}

void output(char name[],float a[3][4] )
{
int i,j;
for(i=0;i<3;i++)
{
printf("\n\nThe %ds student :\n %s ",i+1,name);
for(j=0;j<4;j++)
{
if(j==3)
printf("pingjun\n ");
printf("%f ",a[i][j]);
}
}
}

你这个应该是你们老师留给你的作业吧?
第3个回答  2008-10-31
看看我下面编写的,,对你的帮助可能比较大,,,等我编写好后,在看看我上面的人编写的,,那个占用内存这是大,,如果学生人数很多的,,上面那个人占用的内存将会一直变大,而且他的函数调用竟然还用了数组形参,函数执行效率比较低,而我编写的程序,占用内存小,完全克服了上面那个朋友在占用内存上的问题,程序如下:

#include "stdio.h"

#define memb_count 4 //学生人数

struct student
{
char name[10];
float scedu1;
float scedu2;
float scedu3;
float avg;
};

struct student reslut_table;

//-------输入函数----------------------
void Input(struct student *pTable)
{
printf(" 姓名 \t 课程1 \t 课程2 \t 课程3 \t 平均分 \t\n");
scanf(" %10s \t",pTable->name);
scanf(" %f \t",pTable->scedu1);
scanf(" %f \t",pTable->scedu2);
scanf(" %f \t",pTable->scedu3);
printf("\n");
}
//=====================================

//--------平均值函数-------------------
float Average(struct student *pTable, int N)
{
return(((pTable->scedu1)+(pTable->scedu2)+(pTable->scedu3))/N);
}
//=====================================

//--------输出函数---------------------
void output(struct student *pTable)
{
printf(" 姓名 \t 课程1 \t 课程2 \t 课程3 \t 平均分 \t\n");
printf(" %s \t %f \t %f \t %f \t %f \t\n",
pTable->name,pTable->scedu1,pTable->scedu2,pTable->scedu3,
pTable->avg);
}
//===================================

void main(void)
{
int i;
printf("请输入数据:\n");
for(i=0;i<memb_count;i++)
{
Input(&reslut_table);
reslut_table.avg=Average(&reslut_table,3);
output(&reslut_table);
}
}
第4个回答  2008-10-31
#include<stdio.h>
#define MAX_STU 4
typedef struct
{
char name[50];
int score1;
int score2;
int score3;
}stu;

void input(stu s[],int n);
void output(stu s[],int n);
int average(stu s[],int n);
main()
{
int max_stu=MAX_STU;
stu s[max_stu];
input(s,max_stu);
output(s,max_stu);
}

void input(stu s[],int n)
{
int i=0;
while(i<n){
printf("Please Input Student's Name:");
scanf("%s",&s[i].name);
printf("Please Input Score1,Score2 And Score3(Split By ','):");
scanf("%d,%d,%d",&s[i].score1,&s[i].score2,&s[i].score3);
i++;
}
}
void output(stu s[],int n)
{
int i,avg;
printf("Name \t Scroe1 \t Score2 \t Score3 \t Average \t \n");
for(i=0;i<n;i++){
avg=average(s,i);
printf("%s \t %d \t\t %d \t\t %d \t\t %d \t \n",s[i].name,s[i].score1,s[i].score2,s[i].score3,avg);
}
}
int average(stu s[],int n)
{
int avg;
avg=(s[n].score1+s[n].score2+s[n].score3)/3;
return avg;
}
第5个回答  2008-10-31
现在的学校真应该讲过C基础以后转入数据结构再回头继续c语言
相似回答