C Language

How to Convert Celsius into Fahrenheit in C program

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

 

Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.