Conversion Functions

Lab C Beginner 10 points

Write double c_to_f(double c) and double f_to_c(double f). Read lines like C 100 or F 32 and print the converted value with 1 decimal and the unit.

Input

n, then n lines.

Output

n lines.

Example

Input

3
C 100
F 32
C -40

Output

212.0 F
0.0 C
-40.0 F
Sample input available Sample output available
Editor
C

Hints

" %c" skips the new line left from the previous line.

Solution explanation

Each function does one conversion and is easy to test on its own.

Show solution
#include <stdio.h>

double c_to_f(double c) { return c * 9 / 5 + 32; }
double f_to_c(double f) { return (f - 32) * 5 / 9; }

int main() {
    int n;
    char unit;
    double v;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf(" %c %lf", &unit, &v);
        if (unit == 'C') printf("%.1f F\n", c_to_f(v));
        else printf("%.1f C\n", f_to_c(v));
    }
    return 0;
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD