2、采用结构体数组编写程序,定义一个含职工姓名、工作年限、工资总额的结构体类型,从键盘输入5名职工的信息,最后再对工作年限超过30年的职工加1000元工资,并输出工资变化后的所有职工的信息(要求用下标法和指针法实现)
#include<stdio.h>
struct WORKER
{
char name[20] ;
int worktime ;
int salary ;
};
void Intput ( struct WORKER *p )
{
for ( int i = 0 ; i < 5 ; i ++ )
{
scanf("%s %d %d",(p+i)->name , &(p+i)->worktime , &(p+i)->salary );
}
}
void Output ( struct WORKER *p )
{
for ( int i = 0 ; i < 5 ; i ++ )
{
if ( (p+i)->worktime > 30 )
{
(p+i)->salary += 1000 ;
}
printf("%s %d %d\n",(p+i)->name , (p+i)->worktime , (p+i)->salary );
}
printf("\n");
}
int main (void)
{
struct WORKER wor[5] ;
Intput(wor) ;
Output(wor) ;
return 0 ;
}