猿问

编写input()和output()函数,完成输入和输出5个学生的数据记录?

编写input()和output()函数,完成输入和输出5个学生的数据记录


MM们
浏览 1716回答 2
2回答

炎炎设计

编写input()和output()函数输入,输出5个学生的数据记录。1.程序分析:2.程序源代码:#include "stdio.h"#include "conio.h"#define N 5struct student{char num[6];char name[8];int score[4];}stu[N];input(stu)struct student stu[];{int i,j;for(i=0;i<N;i++){printf("\n please input %d of %d\n",i+1,N);printf("num: ");scanf("%s",stu[i].num);printf("name: ");scanf("%s",stu[i].name);for(j=0;j<3;j++){printf("score %d.",j+1);scanf("%d",&stu[i].score[j]);}printf("\n");}}print(stu)struct student stu[];{int i,j;printf("\nNo. Name Sco1 Sco2 Sco3\n");for(i=0;i<N;i++){printf("%-6s%-10s",stu[i].num,stu[i].name);for(j=0;j<3;j++)printf("%-8d",stu[i].score[j]);printf("\n");}}main(){input();print();getch();}

一只名叫tom的猫

struct student{int num;char name[20];float score[3];}stu[5];void input(struct student stu[5]){int i,j;for(i=0;i<5;i++){scanf("%d,%s",&stu[i].num,&stu[i].name);for(j=0;j<3;j++)scanf("%f",&stu[i].score[j]);}}void output(struct student stu[5]){int i,j;for(i=0;i<5;i++){printf("%d,%s,",stu[i].num,stu[i].name);for(j=0;j<3;j++)printf("%.2f,",stu[i].score[j]);printf("\n");}}main(){input(stu);output(stu);}
随时随地看视频慕课网APP

相关分类

Go
我要回答