

题目
解决代码及点评
/*
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[i].id);
gets_s(sta[i].name);
gets_s(sta[i].sex);
gets_s(sta[i].address);
scanf_s("%d%f",&(sta[i].age),&(sta[i].salary));
}
for (int i = 0; i < N; i++) // 将职工信息输出到屏幕
{
printf("----------------------\n");
puts(sta[i].id);
puts(sta[i].name);
puts(sta[i].sex);
puts(sta[i].address);
printf("%d,%.3f",sta[i].age,sta[i].salary);
}
system("pause");
}
代码编译以及运行
由于资源上传太多,资源频道经常被锁定无法上传资源,同学们可以打开VS2013自己创建工程,步骤如下:
1)新建工程
2)选择工程
3)创建完工程如下图:
4)增加文件,右键点击项目
5)在弹出菜单里做以下选择
6)添加文件
7)拷贝代码与运行
程序运行结果