编写C程序,顺序读入浮点数1、整数、字符、浮点数2,再按照字符、整数、浮点数1、浮点数2的顺序输出。
时间: 2023-06-01 11:02:33 浏览: 52
```c
#include <stdio.h>
int main()
{
float f1, f2;
int i;
char c;
scanf("%f%d %c%f", &f1, &i, &c, &f2);
printf("%c %d %.2f %.2f", c, i, f1, f2);
return 0;
}
```
相关问题
顺序读入浮点数1、整数 字符 浮点数二 再按照字符整数浮点数1浮点数2的顺序输出
代码如下:
```python
f1 = float(input()) # 读入浮点数1
i1 = int(input()) # 读入整数
c = input() # 读入字符
f2 = float(input()) # 读入浮点数2
print(c, i1, f1, f2) # 按照字符整数浮点数1浮点数2的顺序输出
```
输入示例:
```
3.14
42
A
2.718
```
输出示例:
```
A 42 3.14 2.718
```
c语言编写程序,顺序读入浮点数1、整数、字符、浮点数2,再按照字符、整数、浮点数1、浮点数2的顺序输出
你可以按照以下C语言代码编写程序实现:
```
#include<stdio.h>
int main(){
float f1, f2;
int i1;
char c1;
// 顺序读入浮点数1、整数、字符、浮点数2
scanf("%f %d %c %f", &f1, &i1, &c1, &f2);
// 按照字符、整数、浮点数1、浮点数2的顺序输出
printf("%c %d %.2f %.2f", c1, i1, f1, f2);
return 0;
}
```
注意事项:
- 读入浮点数时使用 `%f`,输出浮点数时使用 `%.2f` 控制小数位数;
- 读入字符时使用 `%c`,字符变量只需要使用一个单引号括起来;
- 输出时不要忘记使用空格分隔各个数据类型。
相关推荐
![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)