Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
Function/method to convert Celsius into Fahrenheit -Entered by user

How to Convert Celsius into Fahrenheit in C program

Posted on April 12, 2023April 12, 2023

Table of Contents

  • How to Convert Celsius into Fahrenheit in C program
    • Code to Celsius into Fahrenheit
      • Convert Celsius into Fahrenheit -#1
      • Convert Celsius into Fahrenheit -Entered by the user-#2
      • Convert Celsius into Fahrenheit -Using function-#3
      • Convert Celsius into Fahrenheit Using the function-Entered by the user-#4

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

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes