码迷,mamicode.com
首页 > 其他好文 > 详细

输入两位学生的学号姓名 以及三门成绩 并输出

时间:2019-10-02 00:43:03      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:amp   str   输出   成绩   oid   output   har   printf   i++   

 1 /* 输入学生成绩并显示 */
 2 # include <stdio.h>
 3 
 4 struct student
 5 {
 6     char number[6];
 7     char name[6];
 8     int  score[3];
 9 } stu[2];
10 
11 void output(struct student stu[2]);
12 
13 void main()
14 {
15     int i, j;
16     for(i=0; i<2; i++)
17     {
18         printf("请输入学生%d的成绩:\n", i+1);
19         printf("学号:");
20         scanf("%s", stu[i].number);
21         printf("姓名:");
22         scanf("%s", stu[i].name);
23         for(j=0; j<3; j++)
24         {
25             printf("成绩 %d.  ", j+1);
26             scanf("%d", &stu[i].score[j]);
27         }
28         printf("\n");
29     }
30     output(stu);
31 }
32 
33 void output(struct student stu[2])
34 {
35     int i, j;
36     printf("学号  姓名  成绩1  成绩2  成绩3\n");
37     for(i=0; i<2; i++)
38     {
39         printf("%-6s%-6s", stu[i].number, stu[i].name);
40         for(j=0; j<3; j++)
41             printf("%-8d", stu[i].score[j]);
42         printf("\n");
43     }
44 }

 

输入两位学生的学号姓名 以及三门成绩 并输出

标签:amp   str   输出   成绩   oid   output   har   printf   i++   

原文地址:https://www.cnblogs.com/liugangjiayou/p/11616370.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!