已知a=4,b=5,编程实现:a、b两数互换。程序文件名为36.c。 输入测试数据 a=4 b=5 程序运行结果 a=5,b=4
时间: 2023-05-13 13:05:21 浏览: 48
以下是36.c的代码:
```
#include <stdio.h>
int main() {
int a = 4, b = 5;
int temp = a;
a = b;
b = temp;
printf("a=%d, b=%d", a, b);
return 0;
}
```
输入测试数据 a=4 b=5,程序运行结果 a=5,b=4。
相关问题
编程实现:已知一个人的出生年份,计算其某年的年龄。程序文件名为35.c。 输入测试数据 1966 2021 程序运行结果 2021年 该人的年龄为:55岁
答案:以下是35.c的代码:
```
#include <stdio.h>
#include <stdlib.h>
int main()
{
int birth_year, target_year, age;
printf("请输入出生年份和目标年份(用空格隔开):");
scanf("%d %d", &birth_year, &target_year);
age = target_year - birth_year;
printf("%d年 该人的年龄为:%d岁", target_year, age);
return 0;
}
```
输入测试数据 1966 2021,程序运行结果为:
```
请输入出生年份和目标年份(用空格隔开):1966 2021
2021年 该人的年龄为:55岁
```
注意:这个程序只是一个简单的示例,实际上计算年龄还需要考虑月份和日期的影响。
已知三角形的三边a=3,b=4,c=5,要求输出其面积。C语言
以下是使用C语言计算已知三角形三边长度的面积:
```
#include <stdio.h>
#include <math.h>
int main() {
float a = 3, b = 4, c = 5;
float s, area;
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("三角形的面积为:%f\n", area);
return 0;
}
```
输出结果为:三角形的面积为:6.000000
相关推荐
![](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)