- 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.
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(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.
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
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
- Header File (#include <stdio.h>)
Provides access to input and output functions such as printf() and scanf(). - 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
- Uses a separate function for modularity and code reusability.
- 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
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.


.avif)






