Write a function named tempConvert that accepts a floating p
Solution
#include <stdio.h>
float tempConvert (float ftemp, int ch){
if(ch == \'f\'){
return ((ftemp - 32) * 5)/9;
}
else{
return ftemp*(9/5) + 32;;
}
}
int main()
{
float t;
char ch;
printf(\"Enter the temperature: \");
scanf(\"%f\", &t);
printf(\"Enter the chracter (f or c): \");
scanf(\" %c\", &ch);
printf(\"Temperature is %f\ \", tempConvert(t,ch));
return 0;
}
Output:
sh-4.2$ gcc -o main *.c
sh-4.2$ main
Enter the temperature: 212
Enter the chracter (f or c): f
Temperature is 100.000000
