在第3題的基礎上編寫一個函數input,用來輸入5個學生的成績。

/**************************************************************         
* Copyright (c) 2013, 西華師範大學計算機學院                 
* All rights reserved.                                       
* 作 者:  曾舜堯                                            
* 完成日期:2013 年 05 月 21 日                              
* 工 具:VC6.0                                               
*                                                            
* 輸入描述:                                                 
* 問題描述: 在第3題的基礎上編寫一個函數input,用來輸入5個學生的成績。
* 程序輸出:                                                 
* 問題分析:略                                               
* 算法設計:略                                               
**************************************************************/
#include <stdio.h>
#include <stdlib.h>
#define   N 5/*定義五個學生*/
struct student
{
    int num;
    char name[10];
    float score[3];
};
struct student stu[N];
int main()
{
    void print(int n);/*struct student stu[],int n*/
    /*struct student*/void input (int n);/*struct student stu[],int n*/
      
    printf("\007請輸入五個學生的成績:\n");
    input(N);
    print(N);
    system("pause");
    return 0;
}
void print(/*struct student stu[],*/int n)
{
    int i;
    printf("學號\t姓名\t語文   數學   英語\n");
    for (i=0;i<n;i++)
    {
        printf("%2d\t%s\t%3.2f  %3.2f  %3.2f\n",stu[i].num,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2]);
    }
    //
    return ;
}
/*struct student */void input (/*struct student stu[],*/int n)
{
    int i;
    for (i=0;i<n;i++)
    {
        printf("\007請輸入%d個學生的學號:",i+1);
        scanf("%d",&stu[i].num);
        printf("請輸入姓名:");
        scanf("%s",stu[i].name);
        printf("請輸入是3各科目的成績:");
        scanf("%f%f%f",&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
    }
    return /*stu*/;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章