Table of Contents
How to Convert Celsius into Fahrenheit in C program
In this article, we will discuss the concept of How to Convert Celsius into Fahrenheit in the C program
In this post, we will learn how to write a program to Convert Celsius into Fahrenheit and display the result on the screen in C programming language.
Code to Celsius into Fahrenheit
Convert Celsius into Fahrenheit -#1
In this program, the user declares two variables as Cels and Fahr and initiates the value as 0.0(Celsius). The program will convert from Celsius into Fahrenheit in the C programming language using the scientific equation.
Program 1
#include <stdio.h>
int main() {
// declare variables for celsius and Fahrenheit
float cels,fahr;
//initializing variables
cels=0;
//Convert Celsius to Fahrenheit
fahr=((cels*9/5)+32);
printf("%.2f Celsius into fahrenheit is=%.2f F",cels,fahr);
return 0;
}
When the above code is executed, it produces the following result
0.00 Celsius into Fahrenheit is=32.00 F
Convert Celsius into Fahrenheit -Entered by the user-#2
In this program, the user declares two variables as Celsius and Fahrenheit. The program asks for input from the user for Celsius then the given input will convert from Celsius into Fahrenheit in the C programming language using the scientific equation.
Program 2
// C program to convert celsius into fahrenheit
#include <stdio.h>
int main() {
// declare variables for celsius and fahrenheit
float cels,fahr;
//initializing variables
printf("Enter tempareture in celsius :");//Ask input to Celsius
scanf("%f",&cels);//read input for Celsius
//Convert celsius to fahrenheit
fahr=((cels*9/5)+32);
printf("%.2f Celsius into Fahrenheit is=%.2f F ",cels,fahr);
return 0;
}
When the above code is executed, it produces the following result
Enter temperature in celsius:90 90.00 Celsius into Fahrenheit is=194.00 F
Convert Celsius into Fahrenheit -Using function-#3
In this program, the user declares a double variable as a parameter for Celsius in the user-defined function. When the user runs the program (when calling the function), the given value for Celsius passes as an argument to the function.
Finally, the Fahrenheit value is calculated and displayed on the screen using the scientific equation.
Program 3
// function to convert celsius into fahrenheit using C program
//Entered by user
#include <stdio.h>
float convert_CelsToFahr(float c)
{//user defined function to calculate fahrenheit
return ((c*9.0/5.0)+32.0);
}
int main() {
float fahrenheit=convert_CelsToFahr(0.00);
float fahrenheit1=convert_CelsToFahr(15.00);
float fahrenheit2=convert_CelsToFahr(60.00);
float fahrenheit3=convert_CelsToFahr(75.00);
float fahrenheit4=convert_CelsToFahr(100.00);
//Call the function with argument
printf("Tempareture in fahrenheit:\n");
printf("%.2f\n",fahrenheit);
printf("%.2f\n",fahrenheit1);
printf("%.2f\n",fahrenheit2);
printf("%.2f\n",fahrenheit3);
printf("%.2f",fahrenheit4);
//Dispay result on the screen
return 0;
}
When the above code is executed, it produces the following result
Tempareture in fahrenheit: 32.00 59.00 140.00 167.00 212.00
Convert Celsius into Fahrenheit Using the function-Entered by the user-#4
In this program, the user declares a double variable as a parameter for Celsius in the user-defined function. When the user runs the program (when calling the function), The program asks for input from the user for Celsius and the value for Celsius passes as an argument to the function.
Finally, the Fahrenheit value is calculated and displayed on the screen using the scientific equation.
Program 4
// function to convert celsius into fahrenheit using C program
//Entered by user
#include <stdio.h>
float convert_CelsToFahr(float c)
{
return ((c*9.0/5.0)+32.0);
}
int main() {
// declaring variables
float celsius,fahrenheit;
//ask input rom user
printf("Enter temperature in celsius :");
scanf("%f",&celsius);//reading the input
//Convert celsius to fahrenheit
fahrenheit=convert_CelsToFahr(celsius);
//Call the function with argument
printf("Tempareture in fahrenheit:\n");
printf("%.2f Celsius= %.2f Fahrenheit ",celsius,fahrenheit);
//Dispay result on the screen
return 0;
}
When the above code is executed, it produces the following result
Enter temperature in celsius:100.00 Tempareture in fahrenheit: 100.00 Celsius= 212.00 Fahrenheit
Similar post
Celsius into Fahrenheit in C program
Fahrenheit into Celsius in C program
Celsius into Fahrenheit in C++ program
Fahrenheit into Celsius in C++ program