1. 程式人生 > >Problem X: C語言習題 學生成績輸入和輸出

Problem X: C語言習題 學生成績輸入和輸出

hang output pan log board AR tput 成績 sub

Problem X: C語言習題 學生成績輸入和輸出

Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 4722 Solved: 2284
[Submit][Status][Web Board]

Description

編寫一個函數print,打印一個學生的成績數組,該數組中有5個學生的數據,每個學生的數據包括num(學號)、name(姓名)、score[3](3門課的成績)。編寫一個函數input,用來輸入5個學生的數據。

Input

5個學生的學號,姓名,3門課的成績

Output

5個學生的學號,姓名,3門課的成績

Sample Input

1001 zhangsan 100 90 86
1002 lisi 90 20 80
1003 wangwu 90 90 89
1004 yanping 100 100 100
1005 xiaoxiao 60 60 60

Sample Output

1001 zhangsan 100 90 86
1002 lisi 90 20 80
1003 wangwu 90 90 89
1004 yanping 100 100 100
1005 xiaoxiao 60 60 60

HINT

主函數已給定如下,提交時不需要包含下述主函數
/* C代碼 */
int main()
{
const int n=5;
struct student stu[n];
void input(struct student [],int );
void print(struct student [],int );
input(stu,n);
print(stu,n);
return 0;
}


/* C++代碼 */
int main()
{
const int n=5;
student stu[n];
void input(student [],int );
void print(student [],int );
input(stu,n);
print(stu,n);
return 0;
}
#include<stdio.h>
struct student
{
    int xuehao;
    char name[20];
    int score[3];
}stu;
void input(struct student stu[],int n )
{
    int i,j;
    for(i=0;i<n;i++)
    {
        scanf("%d %s",&stu[i].xuehao,&stu[i].name);
        for(j=0;j<3;j++)
        {
            scanf("%d",&stu[i].score[j]);
        }
    }
}
void print(struct student stu[],int n)
{
    int i,j;
    for(i=0;i<n;i++)
    {
        printf("%d %s",stu[i].xuehao,stu[i].name);
        for(j=0;j<3;j++)
        {
            printf(" %d",stu[i].score[j]);
        }
    printf("\n");
    }
}
int main()


{


    const int n=5;


    struct student stu[n];


    void input(struct student [],int );


    void print(struct student [],int );


    input(stu,n);


    print(stu,n);


    return 0;


}

  

Problem X: C語言習題 學生成績輸入和輸出