用c语言写输入五个浮点数,然后逆序输出它
时间: 2023-08-16 07:05:56 浏览: 88
以下是用C语言实现输入五个浮点数并逆序输出的示例代码:
```c
#include <stdio.h>
int main() {
float nums[5];
int i;
printf("请输入五个浮点数:\n");
for (i = 0; i < 5; i++) {
scanf("%f", &nums[i]);
}
printf("逆序输出:\n");
for (i = 4; i >= 0; i--) {
printf("%.2f ", nums[i]);
}
return 0;
}
```
首先定义一个大小为5的浮点数数组 `nums`,然后使用循环语句 `for` 遍历数组,通过 `scanf` 函数输入五个浮点数。接着使用另一个循环语句 `for` 逆序遍历数组,使用 `printf` 函数输出每个浮点数并在后面加上一个空格。
运行程序后,你可以输入五个任意的浮点数,程序会逆序输出它们。
相关问题
使用c语言实现输入一个浮点数然后倒序输出保留两位小数的浮点数
以下是使用C语言实现输入一个浮点数然后倒序输出保留两位小数的浮点数的代码:
```c
#include <stdio.h>
int main() {
float num;
printf("请输入一个浮点数:");
scanf("%f", &num);
int intPart = (int)num; // 获取整数部分
float decimalPart = num - intPart; // 获取小数部分
printf("倒序输出保留两位小数的浮点数:%.2f\n", decimalPart + intPart / 100.0);
return 0;
}
```
C语言输入一个浮点数,并输出它
的平方根,能给我提供一个程序吗?
当然可以,以下是一段C语言程序,可以实现输入一个浮点数并输出它的平方根:
#include <stdio.h>
#include <math.h>
int main() {
float num; // 定义一个浮点数变量
printf("请输入一个浮点数:\n");
scanf("%f", &num); // 从用户输入中读取浮点数
printf("该数的平方根是:%f\n", sqrt(num)); // 计算并输出平方根
return 0;
}
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.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)