Published: 27 Oct 2025
Reading Time: 7 min read
There are different units to measure temperature, and they are still in use worldwide. Celsius is commonly used to display local weather in countries that use the SI system. Fahrenheit is still in use in places like the USA. Therefore, when discussing temperatures or conducting research, converting degrees Celsius to Fahrenheit is necessary.
Both scales use different reference points and intervals to measure temperature. For example, on a Celsius scale, water's freezing point is 0°C, and its boiling point is 100°C under standard atmospheric pressure. In the Fahrenheit scale, water's freezing point is 32°F, and its boiling point is 212°F.
Many instruments need to perform conversions, and in this article, we will take a look at how to apply a C Program To Convert Celsius to Fahrenheit.
The formula to convert is given by:
T(°F) = (T(°C) × (9/5)) + 32
Where:
The 9/5 fraction is a constant that ensures for the difference in scale between the two temperature systems. Fahrenheit degrees are smaller than Celsius degrees. Specifically, 1°C equals 1.8°F. So when you multiply the Celsius unit by the Fahrenheit scale, going further, adding 32 is needed because 0°C is the freezing point of water in Celsius and in Fahrenheit, it's 32°F. Adding it aligns the freezing point to balance the scale.
Bottom Line: The formula ensures accurate temperature conversion.
The algorithm for Celsius to Fahrenheit C program is as follows:
This topic explains the actual C code used to convert temperature from Celsius to Fahrenheit, illustrating key programming concepts such as logical thinking, mathematical operations, and proper code structure.
The implementation uses functions, formatted input/output, and good commenting practices — similar to foundational C programs such as merge sort, bubble sort, addition of two numbers, and percentage calculation.
#include <stdio.h>
// Function to convert Celsius to Fahrenheit
float convertCelsiusToFahrenheit(float celsius) {
// Perform the mathematical operation for conversion
return (celsius * 9.0 / 5.0) + 32.0;
}
int main() {
float celsius, fahrenheit;
// Prompt user for input
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
// Call function and store result
fahrenheit = convertCelsiusToFahrenheit(celsius);
// Display the result with two decimal places
printf("%.2f Celsius = %.2f Fahrenheit\n", celsius, fahrenheit);
// End of program
return 0;
}
Header File (#include <stdio.h>): Provides access to input and output functions such as printf() and scanf().
Function Definition (convertCelsiusToFahrenheit):
Main Function (int main()):
Enter temperature in Celsius: 37
37.00 Celsius = 98.60 Fahrenheit
Here we talk about doing different mathematical and logical tasks with the help of the C program. Every single example shows the layout, grammar, and the reasoning method of the code that can be employed to tackle actual problems mainly by using mathematical operations, data structures, and algorithms coded in C. None of the programs is lacking the typical form, finishing with return 0, as a way to indicate that everything went well.
#include <stdio.h>
int main() {
int a, b, sum;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum = %d\n", sum);
return 0;
}
Enter two numbers: 8 5
Sum = 13
#include <stdio.h>
int main() {
float s1, s2, s3, s4, s5, total, percentage;
printf("Enter marks of 5 subjects: ");
scanf("%f %f %f %f %f", &s1, &s2, &s3, &s4, &s5);
total = s1 + s2 + s3 + s4 + s5;
percentage = (total / 500) * 100;
printf("Percentage = %.2f%%\n", percentage);
return 0;
}
Enter marks of 5 subjects: 80 75 90 85 70
Percentage = 80.00%
#include <stdio.h>
#define PI 3.1416
int main() {
float radius, area;
printf("Enter radius: ");
scanf("%f", &radius);
area = PI * radius * radius;
printf("Area of circle = %.2f\n", area);
return 0;
}
Enter radius: 7
Area of circle = 153.94
#include <stdio.h>
#include <math.h>
int main() {
float a, b, c, d, root1, root2;
printf("Enter coefficients a, b, c: ");
scanf("%f %f %f", &a, &b, &c);
d = b*b - 4*a*c;
if (d > 0) {
root1 = (-b + sqrt(d)) / (2*a);
root2 = (-b - sqrt(d)) / (2*a);
printf("Roots are real and distinct: %.2f and %.2f\n", root1, root2);
} else if (d == 0) {
root1 = root2 = -b / (2*a);
printf("Roots are real and equal: %.2f\n", root1);
} else {
printf("Roots are imaginary.\n");
}
return 0;
}
Enter coefficients a, b, c: 1 -3 2
Roots are real and distinct: 2.00 and 1.00
#include <stdio.h>
int main() {
int binary, decimal = 0, base = 1, rem;
printf("Enter a binary number: ");
scanf("%d", &binary);
while (binary > 0) {
rem = binary % 10;
decimal = decimal + rem * base;
binary = binary / 10;
base = base * 2;
}
printf("Decimal equivalent = %d\n", decimal);
return 0;
}
Enter a binary number: 1011
Decimal equivalent = 11
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define MAX 100
char stack[MAX];
int top = -1;
void push(char c) { stack[++top] = c; }
char pop() { return stack[top--]; }
int precedence(char c) {
if (c == '^') return 3;
if (c == '*' || c == '/') return 2;
if (c == '+' || c == '-') return 1;
return 0;
}
int main() {
char infix[MAX], postfix[MAX];
int i, j = 0;
printf("Enter infix expression: ");
gets(infix);
for (i = 0; i < strlen(infix); i++) {
char c = infix[i];
if (isalnum(c))
postfix[j++] = c;
else if (c == '(')
push(c);
else if (c == ')') {
while (stack[top] != '(')
postfix[j++] = pop();
pop();
} else {
while (top != -1 && precedence(stack[top]) >= precedence(c))
postfix[j++] = pop();
push(c);
}
}
while (top != -1)
postfix[j++] = pop();
postfix[j] = '\0';
printf("Postfix expression: %s\n", postfix);
return 0;
}
Enter infix expression: A+B*C
Postfix expression: ABC*+
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
void bubbleSort(struct Node* head) {
int swapped;
struct Node *ptr1, *lptr = NULL;
if (head == NULL)
return;
do {
swapped = 0;
ptr1 = head;
while (ptr1->next != lptr) {
if (ptr1->data > ptr1->next->data) {
int temp = ptr1->data;
ptr1->data = ptr1->next->data;
ptr1->next->data = temp;
swapped = 1;
}
ptr1 = ptr1->next;
}
lptr = ptr1;
} while (swapped);
}
void printList(struct Node* n) {
while (n != NULL) {
printf("%d -> ", n->data);
n = n->next;
}
printf("NULL\n");
}
int main() {
struct Node* head = malloc(sizeof(struct Node));
head->data = 4;
head->next = malloc(sizeof(struct Node));
head->next->data = 2;
head->next->next = malloc(sizeof(struct Node));
head->next->next->data = 3;
head->next->next->next = NULL;
printf("Original list: ");
printList(head);
bubbleSort(head);
printf("Sorted list: ");
printList(head);
return 0;
}
Original list: 4 -> 2 -> 3 -> NULL
Sorted list: 2 -> 3 -> 4 -> NULL
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
struct Node* sortedMerge(struct Node* a, struct Node* b) {
if (!a) return b;
if (!b) return a;
if (a->data <= b->data) {
a->next = sortedMerge(a->next, b);
return a;
} else {
b->next = sortedMerge(a, b->next);
return b;
}
}
void frontBackSplit(struct Node* source, struct Node** front, struct Node** back) {
struct Node *slow = source, *fast = source->next;
while (fast) {
fast = fast->next;
if (fast) {
slow = slow->next;
fast = fast->next;
}
}
*front = source;
*back = slow->next;
slow->next = NULL;
}
void mergeSort(struct Node** headRef) {
struct Node* head = *headRef;
struct Node *a, *b;
if (!head || !head->next)
return;
frontBackSplit(head, &a, &b);
mergeSort(&a);
mergeSort(&b);
*headRef = sortedMerge(a, b);
}
void printList(struct Node* node) {
while (node != NULL) {
printf("%d -> ", node->data);
node = node->next;
}
printf("NULL\n");
}
int main() {
struct Node* head = malloc(sizeof(struct Node));
head->data = 10;
head->next = malloc(sizeof(struct Node));
head->next->data = 3;
head->next->next = malloc(sizeof(struct Node));
head->next->next->data = 5;
head->next->next->next = NULL;
printf("Original List:\n");
printList(head);
mergeSort(&head);
printf("Sorted List:\n");
printList(head);
return 0;
}
Original List:
10 -> 3 -> 5 -> NULL
Sorted List:
3 -> 5 -> 10 -> NULL
#include <stdio.h>
int main() {
int num, rev = 0, rem;
printf("Enter a number: ");
scanf("%d", &num);
while (num != 0) {
rem = num % 10;
rev = rev * 10 + rem;
num /= 10;
}
printf("Reversed number = %d\n", rev);
return 0;
}
Enter a number: 1234
Reversed number = 4321
#include <stdio.h>
float convertCelFahrenheit(float c)
{
return ((c * 9.0 / 5.0) + 32.0);
}
int main()
{
float celsius, fahrenheit;
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
//called function to convert celsius to fahrenheit
fahrenheit = convertCelFahrenheit(celsius);
printf("%.2f Celsius = %.2f Fahrenheit", celsius, fahrenheit);
return 0;
}
In the code example above, the conversion fahrenheit into degree celsius is done through a function. The function of convertCelFahrenheit() converts a Celsius value by multiplying by 9/5, then adding 32 to get the Fahrenheit value. In main(), the user gives a Celsius temperature, which is scanned using scanf(). The convertCelFahrenheit() function is invoked as a parameter that contains the given Celsius, and the variable Fahrenheit would contain the result. Last of all, printf() will print the result out. Using a function helps to smear the code clean and allows the conversion code to be called several times.
Enter temperature in Celsius: 0
0.00 Celsius = 32.00 Fahrenheit
=== Code Execution Successful ===
Different testing of your program is a must, and it should be done through <stdio.h>.
First of all, the program should be compiled by a C compiler (like gcc). One of the ways to perform the operation would be:
gcc filename.c -o temp_converter
Don't forget to replace the filename.c with the file name that contains your source code.
Execute the program that you have compiled. The program will use the printf() function to prompt the user for input and, with the help of the scanf() function, it will capture the entered value.
If an input is given, the program will carry out the conversion and use the printf() function to provide the output.
Test Case 1:
User Input: 0
Output:
Enter temperature in Celsius: 0
0.00 Celsius = 32.00 Fahrenheit
Test Case 2:
User Input: 25
Output:
Enter temperature in Celsius: 25
25.00 Celsius = 77.00 Fahrenheit
Test Case 3:
User Input: -10
Output:
Enter temperature in Celsius: -10
-10.00 Celsius = 14.00 Fahrenheit
By testing your program with positive, zero, and negative values, you ensure that your input and output operations are correct and that the conversion is accurate across all scenarios.
For beginning programmers, creating a program to convert degrees centigrade to degrees Fahrenheit is a valuable task because it develops foundational programming concepts, such as input/output, functions, and simple arithmetic. It will also illustrate how to create a problem to develop each part, and then piece these together again in a systematic fashion. This project demonstrates a vital life skill in software development.
When students learn functions, for example, it lays the foundation for more advanced programming topics. In the long term, foundational development concepts will give students greater career potential in software development by developing problem-solving skills and the ability to write clean, reusable code, both of which are critical in the field.
To get started on your professional journey and become job-ready, enroll in the CCBP Academy 4.0 program to build skills that will set you up for a career in software.
The Celsius-to-Fahrenheit C program builds essential skills in user input, arithmetic operations, and modular code, vital for embedded systems, IoT, and scientific apps. It enhances portfolios, fosters problem-solving, and prepares beginners for tech careers in startups and the aerospace industry, where C is key.
The simple major formula to do this is:
Fahrenheit = (Celsius × 9/5) + 32
The temperature conversion programs in C just follow this formula.
The variables representing Celsius and Fahrenheit should be of type float or double. These data types provide decimal values, which are essential for scientific calculations and precise results.
In most cases, the scanf function is the method for user input, allowing the user to enter the Celsius value to be converted by the program.
There are no built-in C libraries for temperature conversions. Still, you may produce your own function to perform these conversions in your code.
In scientific calculations, weather applications, engineering projects, and similar situations, data recorded in differing temperature scales must be processed or compared.
The printf function is used to display the result of the conversion and any prompts or messages to the user on the console.
Yes, creating a custom function (e.g., convertCelsiusToFahrenheit) helps organize code, makes it reusable, and is a good practice in C programming.
The time complexity is O(1), because the program performs the same number of operations regardless of the input value.
Use the proper variables and data types. Your program will be able to accept input and produce output appropriately, which is essential for scientific calculations and handling decimal values.
Many online resources and tutorials provide C programming examples, including programs for merge sort, bubble sort, adding numbers, and other scientific or mathematical operations.
Related Articles:
About NxtWave:
NxtWave offers comprehensive programming courses through CCBP Academy 4.0 to help students build job-ready skills in software development.
Contact Information:
Course Offerings: