任务和代码1
/*
*Copyright (c)2015,CSDN学院
*All rights reserved.
*文件名称:main.c
*作 者:胡先军
*完成日期:2015年5月31日
*版 本 号:v1.0
*
*问题描述:从文件salary.txt中读入工人的工号、基本工资、奖金,
*将奖金全部增加20%(好事)后,将工号、基本工资、奖金和应发工
*资(前项目之和)保存到文件salarylist.txt中
*程序输出:读取数据并保存
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp1,*fp2;
int number;
double salary,reward;
fp1=fopen("salary.txt","r");
if(fp1==NULL)
{
printf("cannot open!\n");
exit(1);
}
fp2=fopen("salarylist.txt","w");
if(fp2==NULL)
{
printf("cannot open!\n");
exit(1);
}
fprintf(fp2,"员工号\t工资\t奖金\t总工资\n");
while(fscanf(fp1,"%d %lf %lf",&number,&salary,&reward)!=EOF)
{
reward=1.2*reward;
fprintf(fp2,"%d %lf %lf %lf\n",number,salary,reward,reward+salary);
}
printf("thanks for your use!");
fclose(fp1);
fclose(fp2);
return 0;
}
运算结果