C语言 计算职工工资

题目描述

给定N个职员的信息,包括姓名、基本工资、浮动工资和支出,要求编写程序顺序输出每位职员的姓名和实发工资(实发工资=基本工资+浮动工资-支出)。

输入

输入在一行中给出正整数N。随后N行,每行给出一位职员的信息,格式为“姓名 基本工资 浮动工资 支出”,中间以空格分隔。其中“姓名”为长度小于10的不包含空白字符的非空字符串,其他输入、输出保证在单精度范围内。

输出

按照输入顺序,每行输出一位职员的姓名和实发工资,间隔一个空格,工资保留2位小数。

样例输入 Copy

3
zhao 240 400 75
qian 360 120 50
zhou 560 150 80

样例输出 Copy

zhao 565.00
qian 430.00
zhou 630.00

代码

#include<stdio.h>
#include<math.h>
#include<string.h> 
#include<stdlib.h>
#define N 100

struct student
{
	char name[10];
	float score[4];
	float total;
}stu[N];

int input(int n)
{
	for(int i=0;i<n;i++)
	{
		scanf("%s %f %f %f",&stu[i].name ,&stu[i].score[0] ,&stu[i].score[1],&stu[i].score[2]);
		stu[i].total =stu[i].score[0]+ stu[i].score[1]-stu[i].score[2];
	}
}

void print(int n)
{
	for(int i=0;i<n;i++)
		printf("%s %.2f\n",stu[i].name,stu[i].total);
}

int main()
{
	int n;
	scanf("%d",&n);
	input(n);
	print(n);
}
发布了47 篇原创文章 · 获赞 29 · 访问量 1495

猜你喜欢

转载自blog.csdn.net/Qianzshuo/article/details/103757884