使用do while输出摄氏度和华氏度的对照表
时间: 2023-04-06 15:00:55 浏览: 108
好的,以下是输出摄氏度和华氏度的对照表的代码:
```
#include <stdio.h>
int main() {
float celsius, fahrenheit;
int lower, upper, step;
lower = 0; // 温度表的下限
upper = 100; // 温度表的上限
step = 10; // 步长
celsius = lower;
printf("摄氏度\t华氏度\n");
do {
fahrenheit = celsius * 9.0 / 5.0 + 32.0;
printf("%3.0f\t%6.1f\n", celsius, fahrenheit);
celsius += step;
} while (celsius <= upper);
return 0;
}
```
希望能对您有所帮助!
相关问题
在java中使用do while输出摄氏度和华氏度的对照表
可以回答这个问题。以下是代码示例:
```
public class TemperatureConverter {
public static void main(String[] args) {
double celsius, fahrenheit;
int lower = 0, upper = 100, step = 10;
System.out.println("摄氏度\t华氏度");
System.out.println("-----------------");
celsius = lower;
do {
fahrenheit = celsius * 9 / 5 + 32;
System.out.printf("%.1f\t%.1f\n", celsius, fahrenheit);
celsius += step;
} while (celsius <= upper);
}
}
```
输出结果如下:
```
摄氏度 华氏度
-----------------
0.0 32.0
10.0 50.0
20.0 68.0
30.0 86.0
40.0 104.0
50.0 122.0
60.0 140.0
70.0 158.0
80.0 176.0
90.0 194.0
100.0 212.0
```
生成摄氏度和华氏度的对照表,使用c语言
好的,下面是生成摄氏度和华氏度对照表的C语言代码:
```
#include <stdio.h>
int main() {
float fahr, celsius;
int lower, upper, step;
lower = 0; // 温度表的下限
upper = 300; // 温度表的上限
step = 20; // 步长
printf("摄氏度\t华氏度\n");
celsius = lower;
while (celsius <= upper) {
fahr = (celsius * 9.0 / 5.0) + 32.0;
printf("%3.0f\t%6.1f\n", celsius, fahr);
celsius = celsius + step;
}
return 0;
}
```
这段代码会生成一个摄氏度和华氏度对照表,从0摄氏度到300摄氏度,步长为20摄氏度。你可以根据需要修改温度表的范围和步长。