Write the following code in c #, Write a method that takes a single argument of type double. The will display a Celsius to Fahrenheit conversion table. The starting temperature is indicated by the argument and it will display 10 lines in increments of 1.[Fahrenheit = 9/5 Celsius + 32]. In your main call this method two times, each time with a different value.
时间: 2024-02-13 14:03:28 浏览: 30
Sure, here is the code you requested:
```csharp
using System;
class Program
{
static void Main(string[] args)
{
double startTemp1 = 0.0;
double startTemp2 = -40.0;
DisplayConversionTable(startTemp1);
Console.WriteLine();
DisplayConversionTable(startTemp2);
}
static void DisplayConversionTable(double startTemp)
{
Console.WriteLine("Celsius\tFahrenheit");
Console.WriteLine("------------------");
for (int i = 0; i < 10; i++)
{
double celsius = startTemp + i;
double fahrenheit = 9.0 / 5.0 * celsius + 32.0;
Console.WriteLine("{0:N2}\t{1:N2}", celsius, fahrenheit);
}
}
}
```
The `DisplayConversionTable` method takes a single argument `startTemp` of type `double`. It then uses a `for` loop to display 10 lines of Celsius to Fahrenheit conversions in increments of 1.
In the `Main` method, we call `DisplayConversionTable` twice, each time with a different starting temperature. The output will be similar to the following:
```
Celsius Fahrenheit
------------------
0.00 32.00
1.00 33.80
2.00 35.60
3.00 37.40
4.00 39.20
5.00 41.00
6.00 42.80
7.00 44.60
8.00 46.40
9.00 48.20
Celsius Fahrenheit
------------------
-40.00 -40.00
-39.00 -38.20
-38.00 -36.40
-37.00 -34.60
-36.00 -32.80
-35.00 -31.00
-34.00 -29.20
-33.00 -27.40
-32.00 -25.60
-31.00 -23.80
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)
![](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)