You are here:

C/program to Convert Celsius to Fahrenheit using C languge

Advertisement


Question
Why isn't this program working properly? please find me where I've got mistaken.


#include <stdio.h>
#include <stdlib.h>

int main()
{
   float c,f;
   printf("Enter temperature in Celsius");
   scanf("%f",c);



   printf("Temperature in Celsius is:%f",c);
   printf("
Temperature in Fahrenheit is:%f",f,c*9/5+32);

   return 0;
}

Answer
Hi Jude,

You need to pass the address of the variable c as a parameter to scanf. Integer division will be rounded down so its better to use floats in the statement that converts celsius to Fahrenheit.

Example:

#include <stdio.h>
#include <stdlib.h>

int main()
{
  float c;
  printf("Enter temperature in Celsius");
  scanf("%f",&c);



  printf("Temperature in Celsius is:%f\n",c);
  printf("Temperature in Fahrenheit is:%f\n",c*(9.0f/5.0f)+32);

  return 0;
}

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tony Nazzal

Expertise

I will answer any c language programming and syntax questions.

Experience

I have almost a decade of c programming experience.

Education/Credentials
I have a bachelor of science degree and several years of industry experience.

©2016 About.com. All rights reserved.