+ 3

How to give combined result of division operation as there are two different operators for displaying quotient and remainder

is it possible by using float datatype for answer variable

28th Jan 2017, 4:14 AM
Uday
Uday - avatar
7 odpowiedzi
+ 7
#include <iostream> using namespace std; int main () { int numerator = 12; int denominator = 5; int div_res = numerator/denominator; int div_rem = numerator%denominator; cout << numerator << "/" << denominator << " is equals to " << div_res << " with remainder of " << div_rem; return 0; }
28th Jan 2017, 4:22 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
yeah it worked.but Iam still confused about that.thank you @subham mittal
28th Jan 2017, 8:20 AM
Uday
Uday - avatar
+ 2
nice but how to show complete answer in decimal value like 15/7=1.5
28th Jan 2017, 4:25 AM
Uday
Uday - avatar
+ 2
you can typecast the denominator into float data type and take div_res as float
28th Jan 2017, 4:31 AM
Shubham Mittal
Shubham Mittal - avatar
+ 2
can you explain it with code @SubhamMittal
28th Jan 2017, 4:33 AM
Uday
Uday - avatar
+ 2
float div_res= numerator/(float) denominator; try this.... this may help you... if your code is in c if it is in c++ then use float (denominator)
28th Jan 2017, 5:29 AM
Shubham Mittal
Shubham Mittal - avatar
+ 2
I can't understand the typecasting of denominator hey are you there
28th Jan 2017, 8:23 AM
Uday
Uday - avatar