c验内容 1.调试,输入一个正整数 n(3<=n<=10),再输入 n 个雇员的信息(如下表所 示),输出每人的姓名和实发工资(基本工资+浮动工资-支出)。
时间: 2023-12-27 13:03:23 浏览: 20
好的,下面是一个可能的 C 代码实现,可以实现您的要求:
```c
#include <stdio.h>
#include <stdlib.h>
int main() {
int n;
scanf("%d", &n); // 输入雇员人数
char name[20];
int basic_salary, floating_salary, expenses;
for (int i = 0; i < n; i++) {
// 输入雇员信息
scanf("%s%d%d%d", name, &basic_salary, &floating_salary, &expenses);
int real_salary = basic_salary + floating_salary - expenses;
printf("%s %d\n", name, real_salary); // 输出姓名和实发工资
}
return 0;
}
```
您可以按照如下格式输入雇员信息:
```
张三 2000 500 300
李四 2500 800 400
王五 1800 300 200
```
其中,每行输入一个雇员信息,用空格分隔姓名、基本工资、浮动工资和支出。程序会输出每个雇员的姓名和实发工资。
相关问题
C语言输入一个正整数n,n<=20;求n的阶层
以下是C语言程序实现:
```c
#include <stdio.h>
int main()
{
int n, i;
unsigned long long factorial = 1; // 使用unsigned long long类型存储阶乘,避免溢出
printf("请输入一个正整数n(n<=20):");
scanf("%d", &n);
// 求阶乘
for (i = 1; i <= n; i++)
{
factorial *= i;
}
printf("%d的阶乘为%llu\n", n, factorial);
return 0;
}
```
该程序使用for循环计算n的阶乘,使用unsigned long long类型存储阶乘,避免因阶乘过大导致计算结果溢出。
用C语言输入一个正整数n,n<=20;求n的阶层
以下是C语言代码:
```c
#include<stdio.h>
int main() {
int n, i, fact=1;
printf("请输入一个正整数n:");
scanf("%d", &n);
if(n<0 || n>20) {
printf("输入的数不符合要求\n");
return 0;
}
for(i=1; i<=n; i++) {
fact *= i;
}
printf("%d的阶乘是:%d\n", n, fact);
return 0;
}
```
运行结果示例:
```
请输入一个正整数n:5
5的阶乘是:120
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)