c = a % b;

Shouldn't c be zero when a = 6 and b=9?

1
2
3
4
5
6
7
8
9
10
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	int a, b, c;
	cin >> a >> b;
	c = a % b;
	cout << c;
}
No. The remainder of 6 divided by 9 is 6.
Don't confuse division remainder (modulo division) (%) with integer division (/). 6 / 9 is 0, 6 % 9 is 6, 9 / 6 is 1, 9 % 6 is 3.
Topic archived. No new replies allowed.