Last Updated: 25 Nov, 2020

Fahrenheit to Celsius

Easy
Asked in company
SYSVINE

Problem statement

Ninja has been assigned to convert temperature from Fahrenheit to Celsius. He has been given a starting Fahrenheit Value (S), ending Fahrenheit value (E), and step size (W). Unfortunately, he does not know how to convert from Fahrenheit to Celsius. Please help him to find the result.

Input Format:
The first line contains an integer 'T' which denotes the number of test cases or queries to be run.

The first line of each test case contains three space-separated integers ‘S’, ‘E’, and ‘W’.
Output Format:
For each case, you need to print all the Fahrenheit-Celsius conversions starting from ‘S’ and ending at ‘E’ with step size ‘W’. Each entry should be printed in a new line and each line should contain the Fahrenheit temperature and the calculated Celsius temperature separated by a space. The output must be converted to the floor value of the integer.

The output of each test case will be printed in a separate line.
Note:
You do not need to input or print anything, and it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 5
1 <= S <= E <= 10000
1 <= W <= 50

Time limit: 1 sec.

Approaches

01 Approach

Here, we can simply run a loop from starting point to the ending point where after each iteration, our loop counter will increase by step size w. For each iteration, we can calculate the celsius temperature and store it in a 2D array.

 

Algorithm:

 

  • Declare a 2D array for storing the result
  • Run a loop from ‘i’ = ‘S’ to ‘E’ with ‘i’ = ‘i’+ ‘W’
    • For each ‘i’, calculate the celsius temperature and put it in the array
  • Return the array