C Lab Lectures Problems/Experiments
Lecture-1:-
Task:- Convert from Fahrenheit to Celcius Program.
#include <stdio.h>
// Fahrenheit to Celcius = C= 5/9 * (F−32)
int main() {
// Declare variables for fahrenheit and celcius
float c , f;
// User inputs value of Fah Temp
printf("Enter Fahrenheit Temp Value:- ");
// Reads the value of fahrenheit
scanf("%f", &f );
// Formula
c = (5.0/9.0) *(f-32);
// Prints the value of Celcius
printf("Temp in Celcius is:- %f", c);
return 0;
}}Problems I faced:-
1. i had the formula after float variable was declared so that's why it didn't work at few attempts.
2. need to put the formula before it's prints/displays the final value of celcius, other code won't work.
#include <stdio.h>
// Fahrenheit to Celcius = C= 5/9 * (F−32)
int main() {
// Declare variables for fahrenheit and celcius
float c , f;
// User inputs value of Fah Temp
printf("Enter Fahrenheit Temp Value:- ");
// Reads the value of fahrenheit
scanf("%f", &f );
// Formula
c = (5.0/9.0) *(f-32);
// Prints the value of Celcius
printf("Temp in Celcius is:- %f", c);
return 0;
}
}1. i had the formula after float variable was declared so that's why it didn't work at few attempts.
2. need to put the formula before it's prints/displays the final value of celcius, other code won't work.
No comments:
Post a Comment