Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C Exercises: Print the corresponding Fahrenheit to Celsius and Celsius to Fahrenheit

C Basic Declarations and Expressions: Exercise-95 with Solution

Write a C program to print the corresponding Fahrenheit to Celsius and Celsius to Fahrenheit.
Both cases initial tempratue = 00, maximum temperature = 1500 and step 100.

Sample Solution:

C Code:

#include <stdio.h>

int main()
{
  float f_temp,c_temp;
  float start_temp, end_temp;
  int STEP;

  start_temp = 0;
  end_temp = 150;
  STEP = 10;
  printf("Fahrenheit to Celsius");
  printf("\n---------------------\n");
  printf("Fahrenheit  Celsius\n");
  while (start_temp <= end_temp)
  {
    f_temp = start_temp * 9 / 5 + 32;
    printf("%6.1f \t %8.1f\n", start_temp, f_temp);    
    start_temp = start_temp + STEP;
  }
  
  start_temp = 0;
  end_temp = 150;
  STEP = 10;
  printf("\n\nCelsius to Fahrenheit\n");
  printf("---------------------\n");
  printf("Celsius   Fahrenheit\n");
  while (start_temp <= end_temp)
  {
    c_temp = (start_temp - 32) * 5 / 9;
    printf("%6.1f \t %8.1f\n", start_temp, c_temp);   
    start_temp = start_temp + STEP;
  }
}

Sample Output:

Fahrenheit to Celsius
---------------------
Fahrenheit  Celsius
   0.0       32.0
  10.0       50.0
  20.0       68.0
  30.0       86.0
  40.0      104.0
  50.0      122.0
  60.0      140.0
  70.0      158.0
  80.0      176.0
  90.0      194.0
 100.0      212.0
 110.0      230.0
 120.0      248.0
 130.0      266.0
 140.0      284.0
 150.0      302.0


Celsius to Fahrenheit
---------------------
Celsius   Fahrenheit
   0.0      -17.8
  10.0      -12.2
  20.0       -6.7
  30.0       -1.1
  40.0        4.4
  50.0       10.0
  60.0       15.6
  70.0       21.1
  80.0       26.7
  90.0       32.2
 100.0       37.8
 110.0       43.3
 120.0       48.9
 130.0       54.4
 140.0       60.0
 150.0       65.6

Flowchart:

C Programming Flowchart: Print the corresponding Fahrenheit to Celsius and Celsius to Fahrenheit.

C programming Code Editor:

Contribute your code and comments through Disqus.

Previous:Write a C program to calculate body mass index and display the grade.
Next: Write a C program to count blanks, tabs, and newlines in an input text.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



C Programming: Tips of the Day

Static variable inside of a function in C

The scope of variable is where the variable name can be seen. Here, x is visible only inside function foo().

The lifetime of a variable is the period over which it exists. If x were defined without the keyword static, the lifetime would be from the entry into foo() to the return from foo(); so it would be re-initialized to 5 on every call.

The keyword static acts to extend the lifetime of a variable to the lifetime of the programme; e.g. initialization occurs once and once only and then the variable retains its value - whatever it has come to be - over all future calls to foo().

Ref : https://bit.ly/3fOq7XP