C++ please check the Description for details | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C++ please check the Description for details

Write a program to calculate the remainder of 234 divided by 13. Remember that the / operator throws away the remainder. Hint: divide 234 by 13 and then multiply it by 13 again

13th Feb 2017, 1:48 PM
John Ugochukwu
John Ugochukwu - avatar
4 Answers
+ 1
234%13 isn't it enough
13th Feb 2017, 4:29 PM
Megatron
Megatron - avatar
0
This is just the way that remainder is calculated if you had to do it yourself. For example if you do this: int x = 5; int y = 2; int z = 5/2; the answer is 2, not 2.5 since z in an int and the answer is "rounded down" since int's cannot handle fractional parts. You can make use of this to calculate the remainder of any division: int r = 234/13; //This gives you the "rounded down" int r = r*13; //Multiply again with original divisor... r = 343 - r; //...and subtract from original number to get the remainder. Or, much easier, do 234%13 to get the same result.
13th Feb 2017, 2:19 PM
Ettienne Gilbert
Ettienne Gilbert - avatar
0
#include <iostream> using namespace std; int main() { cout << "The remainder of 234/13 is " << endl; cout << 234 / 13 * 13 - 234 << endl; return 0;
16th Jul 2017, 4:54 AM
Mafu Tshangela
Mafu Tshangela - avatar
0
#include <iostream> using namespace std; int main() { cout << "The remainder of 234/13 is " << endl; cout << 234 -(234 / 13) * 13 << endl; return 0; }
16th Jul 2017, 5:46 AM
Mafu Tshangela
Mafu Tshangela - avatar