TA的每日心情 | 开心 2014-6-18 08:29 |
---|
签到天数: 14 天 [LV.3]偶尔看看II
滴水大师
 
- 积分
- 2345
|
题目
解决代码及点评
- <pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"></pre><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code">/*
- 1. 定义一个结构体其中包括: 职工号、职工名、性别、年龄、工资、地址。
- 按结构体类型定义一个结构体数组, 从键盘输入每个结构体元素所需的数据,
- 然后逐个输出这些元素的数据(可设数组只有三个元素)。
-
- */
- #include <stdio.h>
- #include <stdlib.h>
- struct staff
- {
- char id[20];
- char name[20];
- char sex[5];
- int age;
- float salary;
- char address[50];
- };
- void main()
- {
- const int N = 3;
- struct staff sta[N];
- for (int i = 0; i < N; i++) // 通过键盘输入3个职工信息
- {
- gets_s(sta.id);
- gets_s(sta.name);
- gets_s(sta.sex);
- gets_s(sta.address);
- scanf_s("%d%f",&(sta.age),&(sta.salary));
- }
-
- for (int i = 0; i < N; i++) // 将职工信息输出到屏幕
- {
- printf("----------------------\n");
- puts(sta.id);
- puts(sta.name);
- puts(sta.sex);
- puts(sta.address);
- printf("%d,%.3f",sta.age,sta.salary);
- }
- system("pause");
- }</pre><br><br></pre></pre>
|
|