Why is my quotient's decimal i.e after dot coming 0 and not precise value

+2 votes
asked Sep 8 by Renuka Aole (140 points)

Write C program to perform division operation on two integer numbers and also print remainder of it.

  Input                        Output

Test case 1        44                            14.6667

                           3                              2           

         

Test case 2        6                               0.8571

                          7                               6

1 Answer

+1 vote
answered Sep 10 by Peter Minarik (7,830 points)

In most programming languages we differentiate between integral and floating point numbers.

If you do integral operation (+, -, *, /, %, etc) the result is also an integral number.

Similarly, the same arithmetic operations applied of floating point numbers will yield floating point results.

E.g.:

  • 3/2 = 1 (only integral parts are kept for integral arithmetic)
  • 3.0 / 2.0 = 1.5. (floating point arithmetic)
  • 4/2 = 2 (integral arithmetic)
  • 4.0 / 2.0 = 2.0 (and not 2 -- floating point arithmetic)
  • 4 / 2.0 = 2.0 (if integrals and floating points are mixed, the result is floating point)
You can google around to see how exactly integral and floating point arithmetic work in C.
I hope this helped.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...