Contest 2:Temperature Conversion

本文介绍了一个简单的C程序,用于实现摄氏度与华氏度之间的相互转换。输入包括多个温度值及其对应的单位(摄氏度或华氏度),程序将输出相应的转换结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

Fahrenheit(F) and Centigrade(C) are used as unit of measuring the temperature. The conversion between them is: F = 32 + C*1.8; C = (F - 32)/1.8
We need you write a C program to convert temperature value under different unit.

Input

The input consists of n+1 lines.
There is one integer n which is the number of test cases in the first line.
From  2nd to last line, there are a char and a float number in each line, which represent the type and temperature value. Two elements are seperated by a space. A 'C' represent the Centigrade temperature  and an 'F' for Fahrenheit temperature. You need convert Centigrade temperature to Fahrenheit temperature, vice versa.

Output

The ounput consists of n lines. Each contains a float value which is converted result. No return charactor for the last line.
The float value should retain 2 digits after the decimal point.

here is a sample,

input:
2
C 10.30
F 90.41

output:
50.54
32.45

Because
C->F: 32+10.3*1.8 = 50.54
F->C: (90.41-32)/1.8 = 32.45

Sample Input

2
C 10.30
F 90.41

Sample Output

50.54
32.45

HINT

#include <stdio.h>
#include <stdlib.h>

int main()
  { char ch;
    int n,i;
    scanf("%d\n",&n);
    float a[n];
    for(i=1;i<=n;i++){
    scanf("\n%c%f",&ch,&a[i]);
    int b=ch;
    if(b==67)
    a[i]=32+a[i]*1.8;
    else if(b==70)
    a[i]= (a[i]-32)/1.8;}
    for(i=1;i<=n;i++){
    printf("%.2f\n",a[i]);}
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值