Fill your College Details

Summarise With AI
ChatGPT
Perplexity
Claude
Gemini
Grok
ChatGPT
Perplexity
Claude
Gemini
Grok
Back

C Program To Convert Celsius To Fahrenheit

27 Oct 2025
7 min read

Key Takeaways From The Blog

  • Theβ€‹β€β€‹β€Œβ€β€‹β€β€Œβ€‹β€β€‹β€Œβ€β€‹β€β€Œ formula F = (C Γ— 9/5) + 32 is carried out in C through the use of floating-point variables for decimal accuracy, thus giving correct temperature conversions in situations like weather forecasting.
  • By using a function such as convert Celsius to Fahrenheit to isolate the logical part, the code becomes reusable, maintainable, and consistent with professional coding standards.
  • The scanf function obtains user input, while printf displays formatted output (for example, with two decimal places), which is essential for interactive C programs.
  • Testing with diverse inputs (e.g., 0Β°C, 25Β°C, -10Β°C) ensures reliability, a key skill for debugging real-world applications.
  • Mastering this and related programs (e.g., addition, percentage) builds logical thinking and prepares beginners for complex C projects in 2025 tech roles.

Introduction

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.

Formula to Convert Degree Celsius into Fahrenheit

The formula to convert is given by:Β 

T(oF) = (T(oC) Γ— (9/5)) + 32

Where T(oF) is the temperature in Fahrenheit

(T(oC) is the temperature in CelsiusΒ 

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.

Algorithm For C Program to Convert Celsius to Fahrenheit

The algorithm for Celsius to Fahrenheit C program is as follows:Β 

  • Start
  • Input the temperature in CelsiusΒ 
  • Apply the conversion formula: T(oF) = (T(oC) Γ— (9/5)) + 32
  • Output the temperature in FahrenheitΒ 
  • End

C Program Implementation for Celsius to Fahrenheit Conversion

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.

Program

#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;
}

Explanation

  1. Header File (#include <stdio.h>)
    Provides access to input and output functions such as printf() and scanf().
  2. Function Definition (convertCelsiusToFahrenheit)
    • Uses a separate function for modularity and code reusability.

    • Performs the mathematical operation:
      F=(CΓ—95)+32F = (C \times \frac{9}{5}) + 32F=(CΓ—59​)+32
  3. Main Function (int main())
    • Prompts the user to input temperature in Celsius.
    • Calls the conversion function and stores the result in the fahrenheit variable.
    • Displays formatted output with two decimal places for clarity.
    • Ends with the return 0; statement, signifying successful execution.

Sample Output

Enter temperature in Celsius: 37

37.00 Celsius = 98.60 Fahrenheit

Code Implementation of Celsius to Fahrenheit in a C Program

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.

1. C Program to Add Two Numbers

#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;
}

Explanation

  • The program takes two integers as input.
  • It performs a mathematical operation (addition) and stores the result in the sum variable.
  • Finally, it displays the sum on the screen.

Sample Output

Enter two numbers: 8 5

Sum = 13

2. C Program to Calculate the Percentage of 5 Subjects

#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;
}

Explanation

  • Takes marks of 5 subjects as input.

  • Calculates total and percentage using basic mathematical operations.

  • The output shows percentages up to two decimal places.

Sample Output

Enter marks of 5 subjects: 80 75 90 85 70

Percentage = 80.00%

3. C Program to Find Area of a Circle

#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;
}

Explanation

  • Uses the formula area = Ο€ Γ— rΒ².

  • Demonstrates the use of constants and mathematical operations.

Sample Output

Enter radius: 7

Area of circle = 153.94

4. C Program to Find Roots of a Quadratic Equation

#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;
}

Explanation

  • Uses logical thinking to decide the nature of roots based on the discriminant d.
  • Uses conditional statements and math library functions.

Sample Output

Enter coefficients a, b, c: 1 -3 2

Roots are real and distinct: 2.00 and 1.00

5. C Program to Convert Binary Number to Decimal Number

#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;
}

Explanation

  • Converts binary digits to decimal by multiplying each bit by its positional value.
  • Demonstrates the use of loops and mathematical logic.

Sample Output

Enter a binary number: 1011

Decimal equivalent = 11

6. C Program to Convert Infix to Postfix

#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;
}

Explanation

  • Converts an infix expression (e.g., A+B*C) into postfix form (ABC*+) using a stack.
  • Demonstrates stack operations and logical precedence handling.

Sample Output

Enter infix expression: A+B*C

Postfix expression: ABC*+

7. C Program for Performing Bubble Sort on Linked List

#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;
}

Explanation

  • Implements the bubble sort algorithm on a linked list using data swapping.
  • Demonstrates pointer manipulation and iterative logic.

Sample Output

Original list: 4 -> 2 -> 3 -> NULL

Sorted list: 2 -> 3 -> 4 -> NULL

8. C Program for Merge Sort for Linked Lists

#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;
}

Explanation

  • Implements merge sort for linked lists using recursion.
  • Demonstrates divide-and-conquer and pointer handling.
  • More efficient than bubble sort for larger lists.

Sample Output

Original List:

10 -> 3 -> 5 -> NULL

Sorted List:

3 -> 5 -> 10 -> NULL

9. C Program to Reverse a Number

#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;
}

Explanation

  • Uses a loop and modulus operation to extract digits.

  • Demonstrates logical thinking in reversing a number step by step.

Sample Output

Enter a number: 1234

Reversed number = 4321

Key Takeaways So Far

  • Aβ€‹β€β€‹β€Œβ€β€‹β€β€Œβ€‹β€β€‹β€Œβ€β€‹β€β€Œ function such as convert CelsiusToFahrenheit helps to keep the code clean and makes it reusable.Β 
  • The float data type is used for exact temperature calculations.Β 
  • The program uses scanf and printf to get input from the user and display the output.

🎯 Calculate your GPA instantly β€” No formulas needed!!

C Program to Convert Fahrenheit into Degree Celsius Using Functions

#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;
}

Explanation

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.

Output

Enter temperature in Celsius: 0
0.00 Celsius = 32.00 Fahrenheit

=== Code Execution Successful ===

‍Key Takeaways So Far

  • Additional programs (addition, percentage) reinforce input/output and math operations.
  • Consistent use of return 0 ensures successful program termination.
  • These examples build logical thinking for more complex C tasks.

Testing and Output

Differentβ€‹β€β€‹β€Œβ€β€‹β€β€Œβ€‹β€β€‹β€Œβ€β€‹β€β€Œ testing of your program is a must, and it should be done through <stdio>.

1. Compiling the Program

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.

2. Running and Testing the Program

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.

3. Input and Output Operations

The printf() function shows the messages to the user, such as "Enter temperature in Celsius:".The scanf() function is the one that takes the user's input for further processing.

4. Displaying the Result

If an input is given, the program will carry out the conversion and use the printf() function to provide the β€‹β€β€‹β€Œβ€β€‹β€β€Œβ€‹β€β€‹β€Œβ€β€‹β€β€Œoutput.

Sample Testing Scenarios and Expected 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

Summary of Testing Steps:

  • Compile the program.
  • Run the executable.
  • Enter different Celsius values as user input.
  • Observe the output displayed via printf().

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.

Conclusion

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.

Why It Matters?

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.

Practical Advice for Learners

  • Write and test the program with different inputs.Β 
  • Use functions to create reusable code.
  • Recreate with other programs (e.g., calculating percentages).
  • Debug with gcc and check the console output.
  • Try to code in online C compilers

Frequently Asked Questions

1.β€‹β€β€‹β€Œβ€β€‹β€β€Œβ€‹β€β€‹β€Œβ€β€‹β€β€ŒWhatβ€‹β€β€‹β€Œβ€β€‹β€β€Œ is the conversion formula used in C programming examples for Celsius to Fahrenheit?

The simple major formula to do this is:

Fahrenheit = (Celsius Γ— 9/5) + 32

The temperature conversion programs in C just follow this formula.

2. Which data types are best for storing temperature values in C programs?

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.

3. How is user input handled in a C program for temperature conversion?

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.

4. Are there any built-in libraries in C for temperature conversions?

There are no built-in C libraries for temperature conversions. Still, you may produce your own function to perform these conversions in your β€‹β€β€‹β€Œβ€β€‹β€β€Œcode.

5. What are some common programming scenarios where temperature conversion is needed?

In scientific calculations, weather applications, engineering projects, and similar situations, data recorded in differing temperature scales must be processed or compared.

6. How does console output work in these C programming examples?

The printf function is used to display the result of the conversion and any prompts or messages to the user on the console.

7. Can I use custom functions to organize my C program for temperature conversion?

Yes, creating a custom function (e.g., convertCelsiusToFahrenheit) helps organize code, makes it reusable, and is a good practice in C programming.

8.β€‹β€β€‹β€Œβ€β€‹β€β€Œβ€‹β€β€‹β€Œβ€β€‹β€β€Œ What is the time complexity of a typical Celsius to Fahrenheit conversion program?

The time complexity is O(1), because the program performs the same number of operations regardless of the input value.

9. Why is it important to understand variables and data types in temperature conversion programs?

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.

10. Where can I find more C programming examples related to temperature conversions and other topics?

Many online resources and tutorials provide C programming examples, including programs for merge sort, bubble sort, adding numbers, and other scientific or mathematical operations.

Read More Articles

Chat with us
Chat with us
Talk to career expert