# Thread: Simple division program help

1. ## Simple division program help (added a new question)

My initial problem has been solved, i have another question, is it possible for me to check whether each digit of an entered number is odd or even? for example 121 was entered' how do I apply (number % 2 == 0) command to each separate digit?

Basicaly: I want to find out if the sum of all the even digits equalls the sum of all the odd digits
Hello, I am trying to create a program that can tell me if the number I type in can be divided by 11 without any remains.

For example if i type in 121 it will answer "yes" while if I type in 139 it will say no.

I have started learning c around two hours ago and have been aiming to make this program all along...unfortunately i have failed.

If someone has the time could you please write this simple program for me and explain any complicated parts.

Andrey

2. No. Post your own code and explain what you're having problems with.

Quzah.

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

int main()
{
int this_is_a_number;

printf( "Please enter a number: " );
scanf( "%d", &this_is_a_number );

if (this_is_a_number / 11 = /* whole number/*) (printf ("yes"));
else (printf ("no"));
}```
unfortunately this is as far as i got' I have no idea on how to continue.

5. You can use the modulo ('%') operator to find the remainder, eg:

121 % 10 is 1, so not evenly divisible
121 % 11 is 0, so the number is evenly divisible by 11

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

int main()
{
int this_is_a_number;

printf( "Please enter a number: " );
scanf( "%d", &this_is_a_number );

if (this_is_a_number % 11 == 0) (printf ("yes"));
else (printf ("no"));

return 0;
}```
Thank you very much quzah for not writing the code for me but rather making me write it myself and thank you very much rags_to_riches for telling me what to look for.

7. On your if/else, remember that { } is a new block of code / scope level, and () is more of operator.
Code:
```if( x )
{
...this...
...can have multiple lines...
...including declaring new varaibles...
}
else
{
...same here...
}```
Quzah.

8. Originally Posted by Syle
Code:
```#include <stdio.h>

int main()
{
int this_is_a_number;

printf( "Please enter a number: " );
scanf( "%d", &this_is_a_number );

if (this_is_a_number % 11 == 0) (printf ("yes"));
else (printf ("no"));

return 0;
}```
Thank you very much quzah for not writing the code for me but rather making me write it myself and thank you very much rags_to_riches for telling me what to look for.

Just nitpicking here, but you don't need the parenthesis around the printf statement, and you should indent your code properly, eg:

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

int main()
{
int this_is_a_number;
printf( "Please enter a number: " );
scanf( "%d", &this_is_a_number );
if (this_is_a_number % 11 == 0)
printf ("yes");
else
printf ("no");
return 0;
}```

9. Thank you all once again, if possible could you adress my second question?

10. I don't see a second question anywhere. What's your question?

Quzah.

11. You don't need to separate the digits - if the entire number is evenly divisible by two it's, well, even.

12. That is not what i want to check though, I want to find out if the sum of all the even digits equalls the sum of all the odd digits.

Quzah I have added my second question to the initial post.

13. Then you need to add up all the digits where %2 == 1, and all the ones that %2 == 0 in another variable. So, that means you need two different varaibles, and to use an if check to decide which one gets incremented by whatever. Give it a shot, let us know what you get stuck on.

Quzah.

14. That is not the part I am having trouble with, I am having trouble with finding a way to adress each digit.

int this_is_a_number;
printf( "Please enter a number: " );
scanf( "%d", &this_is_a_number );
After this command how do I separate the digits of the entered number?

15. How do you split the 1s place from a number? Mod by 10.
How do you split digit X from a number? Divide by 10 ... or 100, or 1000. Or just divide by 10 over and over.

Quzah.