tim3in tim3in - 2 months ago 21
C Question

Modulus operator in C?

i need to know how modulus operator work in C?
please read my code

#include <stdio.h>

int main(void)
{
int n;
n=1%10;
printf("%d",n);
}


the result is:
1

please tell me how does the result 1 is produced.

i know how modulus operator work i just wanted to know how the number less than 10 if modulus by 10 always result in the number itself.

i.e.
2%10 is equal to 2 and
3%10 is equal to 3 and
7%10 is equal to 7
etc.

Answer

Yeah it will give 1.

int main(void)
{
    int n;
    n=1%10;
    printf("%d",n);
}

How?

Use Simple math,

10) 1 (0
   -0
   ___
    1

When you divide 1 by 10,

10 * 0 = 0
1 - 0  = 1

So the reminder will be 1.