Fahrenheit to Celsius
Level EASY
Given three values - Start Fahrenheit Value (S), End Fahrenheit value (E) and Step Size (W), you need to convert all Fahrenheit values from Start to End at the gap of W, into their corresponding Celsius values and print the table.
Input Format :
Output Format :
Fahrenheit to Celsius conversion table. One line for every
Fahrenheit and corresponding Celsius value. On Fahrenheit value and its
corresponding Celsius value should be separate by tab ("\t")
Constraints :
Sample Input 1:
Sample Output 1:
Sample Input 2:
Sample Output 2:
Explanation For Input 2:
We need need to start calculating the Celsius values for each of
the Fahrenheit Value which starts from 20.
So starting from 20 which is the given Fahrenheit start value, we need
to compute its corresponding Celsius value which computes
to -6. We print this information as <Fahrenheit Value> a tab
space"\t" <Celsius Value> on each line for each step of 13
we take to get the next value of Fahrenheit and extend this
idea till we reach the end that is till 119 in this case.
You may or may not exactly land on the end value depending on the
steps you are taking.
Not happy with this solution
ReplyDeletethe constraints of s and w are not covered in this code
ReplyDeleteimport java.util.Scanner;
ReplyDeletepublic class Solution {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int S = s.nextInt(); // 0
int E = s.nextInt(); //100
int dif = s.nextInt(); //10
while(S<=E){
int cel = ((S-32)*5)/9;
System.out.println(S+"\t"+cel);
S=S+dif;
}
}
}
I THINK THIS WILL SURELY HELP YOU.
thx
DeleteThis should do the job:
ReplyDelete#include
using namespace std;
int main()
{
int S,E,W,i,cd;
cin>>S;
cin>>E;
cin>>W;
while (((S>=0)&&(S<=80)) && ((E>=S)&&(S<=900)) && ((W>=0)&&(W<=40)))
{
while(S<=E)
{
for(i=S;i<=E;i+=W)
{
cd=(i-32)/1.8;
cout<<i<<"\t"<<cd<<"\n";
S+=W;
}
}
}
}
nice
ReplyDelete