首页 > 解决方案 > Add floating point numbers 23.54 and 33.22 with just integral value like 23+33

问题描述

There are two floating point numbers 23.54 and 33.22 have to make a program to add them with just left side integral value like 23+33=56.

Here's the code that I tried:

screenshot of code

标签: cfloating-point

解决方案


int sum;
sum=(int)num1+(int)num2;
printf("%d",sum);

or

printf("%d",(int)num1+(int)num2);

The datatype of num1 is float and I'm using (int) to typecast to integer type.
Since we typecast the datatype this is called explicit typecasting!


推荐阅读