+ 1
how to add integer part of the decimal numbers by c language
https://prnt.sc/1x85esy https://prnt.sc/1x85gmq https://prnt.sc/1x85i04 https://prnt.sc/1x85j4p and this is the code I have done https://code.sololearn.com/cP2VMloNnJ94 Can anyone help me with saying where I went wrong
10 ответов
+ 3
Your code seem to be correct i guess their is constraints that yiur input number should be between
0.00 to 500.00 so after input u need to check thats number is between given constraints or not
Like this
If( numb1>=0&&numb1<=500)
+ 3
You need to use modf() function from <math.h>. The function's purpose is to break a floating point value into integral and fractional parts.
http://www.cplusplus.com/reference/cmath/modf/
Once you extracted the integral parts of the two numbers, you can then convert them into int values before summing up.
+ 3
Simple. You change the numbers to integers before adding. Problem solved
https://code.sololearn.com/cS1sQ3pd7TtA/?ref=app
+ 3
Thank you
+ 3
shravya Happy to help =)
+ 2
Its working but I am not getting expected output when I keep my input as :-99.26
34.99
I should get output as :133 but I am getting it as 134
+ 2
And there is another reason why I took int because it's given in mandatory test case 2 that it should be taken int sum;
+ 1
It works fine, you just have an extra pound on the first line. Delete one
+ 1
Ahh, that because the sum variable is an integer. An integer can't be a float unless cast, so switch the declaration from an int to a float
shravya
https://code.sololearn.com/cNjIWXyp1NEO/?ref=app
+ 1
Then I am getting output like 134.25 but I want 133