Here is a C program to convert temperature in Centigrade to Fahrenheit with output and proper explanation. This is be done using normal arithmetic operations like addition and multiplication. All you need is the conversion formula.
Formula: The formula to convert Centigrade to Fahrenheit is - F = 1.8 * C + 32
# include <stdio.h> # include <conio.h> void main() { float c, f ; clrscr() ; printf("Enter the centigrade : ") ; scanf("%f", &c) ; f = (1.8 * c + 32) ; printf("\nThe farenheit is : %.2f", f) ; getch() ; }
Note: In above program %f is used for inputting and outputting float (decimal) values while %.2f is used to print values up to precision of two digits after decimal.
Output of above program is
Enter the centigrade : 50
The farenheit is : 122.00
Explanation of above program
The program is very simple to understand. All we're doing is just using the formula and applying the arithmetic operations to make the conversion of Centigrade to Fahrenheit.
why have we taken both cen and fah as float. centigrade could have been in int.
Hello Tanmay,
Great post. Well thought out. This piece reminds me when I was starting out Converting Centigrade to Fahrenheit using C after graduating from college.
int main ()
{
int a=7, t=0;
t=--a+--a+a+++a;
printf("%d",t);
}
output: 20
I could not understand why it prints '20' ?
A type cast should not be used to override a const or volatile declaration. Overriding these type modifiers can cause the program to fail to run correctly. A type cast should not be used to turn a pointer to one type of structure or data type into another. In the rare events in which this action is beneficial, using a union to hold the values makes the programmer’s intentions clearer.
By the way do you have any YouTube videos, would love to watch it. I would like to connect you on LinkedIn, great to have experts like you in my connection (In case, if you don’t have any issues).
Regards,
Anny