日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

c語言結(jié)構(gòu)體和共用體1.有5個學生,每個學生的數(shù)據(jù)包括學號、姓名、3門課的成績,從鍵盤輸入5個學生數(shù)據(jù)

 lixinhecom 2017-07-17
#include<stdio.h>
#define max 5 /*設定要輸入成績的學生個數(shù)*/

double zpj; /*總平均值*/
struct student /*結(jié)構(gòu)體*/
{
int num;
char name[10];
int score1;
int score2;
int score3;
double pj;
};
struct student stu[max],temp;

void Input() /*輸入函數(shù)*/
{ int i;
for(i=0;i<max;i++)
{printf("enter number"); scanf("%d",&stu[i].num); printf("enter name"); scanf("%s",&stu[i].name); printf("enter score1"); scanf("%d",&stu[i].score1); printf("enter score2"); scanf("%d",&stu[i].score2); printf("enter score3"); scanf("%d",&stu[i].score3); }
}

average() /*求平均值函數(shù)*/

{int i; for(i=0;i<5;i++) {stu[i].pj=stu[i].score1+stu[i].score1+stu[i].score3; zpj+=stu[i].pj; }
for(i=0;i<5;i++)
stu[i].pj/=3;
zpj/=max;
}

MAX() /*找出最高平均值的學生的函數(shù)*/
{int i,j; temp=stu[0]; for(i=0;i<max-1;i++) for(j=i+1;j<max;j++) if(stu[i].pj<stu[j].pj) temp=stu[j]; }





output() /*輸出函數(shù)*/

{int i; for(i=0;i<max;i++) printf("num=%d\n name=%s\n score1=%d\n score2=%d\n score3=%d\n aver=%f\n", stu[i].num,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].pj); printf("總平均分=%f\n\n",zpj); printf("平均分最高的學生\nnum=%d\n name=%s\n score1=%d\n score2=%d\n score3=%d\n aver=%f\n", temp.num,temp.name,temp.score1,temp.score2,temp.score3,temp.pj); }
void main() /*主函數(shù)*/
{

Input();
average();
MAX();
output();
}



自己寫的 符合你的要求
不足之處還請指教

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多