Home > Blockchain >  Add floating point numbers 23.54 and 33.22 with just integral value like 23 33
Add floating point numbers 23.54 and 33.22 with just integral value like 23 33

Time:10-10

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

CodePudding user response:

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!

CodePudding user response:

#include <stdio.h>

int main(){



float sum;
float num1;  
float num2;
printf("first number:");
scanf("%f",&num1);
printf("second number:");
scanf("%f",&num2);
sum=(int)num1 int(num2);
printf("sum is %.2f",sum);
}
  • Related