decimal of numbers in c

The error is that %d in the format specifier of both scanf and printf represents decimal, so it expects an int (in the case of scanf, a pointer to int)

Since you are declaring b and c as float, %d in the lines

scanf("%d",&b);

printf("%d lbs is %d kgs.",b,c);

should be changed to %f respectively.

A little piece of advice: use double in stead of float. It provides more precision, its performance is better in many machines. The downside is that it occupies more space than float, but that’s not a problem in most cases.

You should use %f in printf and %lf in scanf in case you are using double.

Leave a Comment