# Illidari's Newb Question #1

This is a discussion on Illidari's Newb Question #1 within the C Programming forums, part of the General Programming Boards category; Okay I am trying to teach myself C programming I am sure I will have many questions lol :P So ...

1. ## Illidari's Newb Question #1

Okay I am trying to teach myself C programming

I am sure I will have many questions lol :P

So I am using notes and an example:

Code:
```#include <stdio.h>
#include <math.h>

int main (void) {
char ch;
int x,y;

ch = 'j';
x = 6*2;
y = 3*x - 50% x;

printf("y = %d\n", y);

system("Pause");
return 0;
}```

Why does this print y= 34 at 50%, 26 at 10% and 28 at 20%

I can't figure out the pattern. What does that percent sign do to the equation. Currently set to 50% in the code.

2. Percent is the modulo operator. It returns the value of the of the remainder of dividing the first number by the latter.

e.g. 10%3 = 1

because 10 divided by 3 is quotient 3, remainder 1.

3. In your case y = 3*12 + 50%12 which is 36 + 2 = 38.

4. Thank you good sir ^_^ That was quick.

5. My pleasure.

Popular pages Recent additions