tim3in - 4 months ago 69

C Question

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.

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.