Modulus operator: Why does this output to 18?

closed account (Siz8AqkS)
1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;
int main ()
{
    int c;
    c=(3%4)*6;
    cout<<c;
    return 0;
}
Do you know what 3%4 means and what value it gives?
closed account (Siz8AqkS)
I don't know what it means but from the output its value is 3.
3%4 gives the remainder from the division 3/4.

If you have a%b it gives the value of a-(a/b)*b.
Last edited on
Topic archived. No new replies allowed.