1. Complex C questions

I am ok at programming but I don't get how to compare the number back to check if it's composed of the same numbers in this problem. Even general tips would b super!,
i have so far made a function for multiplying the user inputted number to obtain the number that will need testing for whether it is an anagram or notI am however aware that it has quite a lot wrong with it :P I have other code but this is a little annoying. Also how can I compare the numbers within the user inputted number (if that makes sense)

Code:
```void multiplyNumber(int userInput)

while(multiplyBy<9)
{
int multiplyBy = 2;
userInput*multiplyBy = anagramToTest1;
multiplyBy++;

}```
An anagram number is a number that can be multiplied by at least one single digit number (other than 1)
to become an anagram of itself. Any anagrams formed by multiplying an anagram number by a digit are
said to be generated by that anagram number. Two numbers are anagrams of each other if they can both
be formed by rearranging the same combination of digits.
For example:
• 1246878 is an anagram number; multiplying by 6 generates 7481268 or by 7 generates 8728146.
These numbers all contain a single 1, 2, 4, 6, 7 and two 8s.
• 1246879 is not an anagram number.
1(a)
Write a program which reads in a single number (between 1 and 123456789 inclusive)
and determines if it is an anagram number.
If the number is not an anagram number you should output the word NO. If it is an
anagram number you should output each single digit it can be multiplied by to make
an anagram of itself.

2. The clue is in the first bullet point/example your teacher gave:
These numbers all contain a single 1, 2, 4, 6, 7 and two 8s.
You need to count the number of each digit (0-9) in the original and again in the product of original * some_digit. If the counts of all the digits match, you have an anagram.

3. You could create two arrays that keep counts of the digits in each number:
Code:
```void count_digits(int num, int *values)
{
while(num)
{
values[num % 10]++;
num /= 10;
}
}

int main(void)
{
int num1 = 1246878;
int num2 = 8728146;
int num1values[10];
int num2values[10];
int i;

count_digits(num1, num1values);
count_digits(num2, num2values);

for(i = 0;i < 10;++i)
if(num1values[i] != num2values[i])
{
puts("Not an anagram number");
break;
}

if(i == 10)
puts("It is an anagram");

return 0;
}```
That would test one number against another anyway. I haven't tested the code so there might be errors. You get the idea though.

4. We shouldn't be doing the entire homework assignment for people. As a poster of 2450+ posts you should know that.

5. Originally Posted by nonoob
We shouldn't be doing the entire homework assignment for people. As a poster of 2450+ posts you should know that.
It's not the entire homework assignment. Look again.

6. Originally Posted by itsme86
You could create two arrays that keep counts of the digits in each number:
Code:
```void count_digits(int num, int *values)
{
while(num)
{
values[num % 10]++;
num /= 10;
}
}

int main(void)
{
int num1 = 1246878;
int num2 = 8728146;
int num1values[10];
int num2values[10];
int i;

count_digits(num1, num1values);
count_digits(num2, num2values);

for(i = 0;i < 10;++i)
if(num1values[i] != num2values[i])
{
puts("Not an anagram number");
break;
}

if(i == 10)
puts("It is an anagram");

return 0;
}```
That would test one number against another anyway. I haven't tested the code so there might be errors. You get the idea though.
Wow thanks so much , so basically I was having trouble with having to compare the numbers you get from the multiple steps (like testing for division by 2-9) and seeing if they're anagrams, and this piece of code (forgive my stupidity but I'm a bit of a beginner at this :P ) will allow me to compare the individual numbers contained within the one imputed by the user to the product of my multiplication? If it's not too much to ask (I'm a bit of a beginner so it's probably obvious to someone like you) , how exactly does is it doing this?

7. Basically, it's keeping a count of each digit of the number in an array. When count_digits() returns, values[0] will have the number of 0s in the number, values[1] will have the number of 1s, etc. Then you just compare the arrays.

8. Originally Posted by nonoob
We shouldn't be doing the entire homework assignment for people. As a poster of 2450+ posts you should know that.
I'm really sorry if that's what it came across as, but I was just trying to understand this because I'm sort of a beginner, and on the contrary I do not want anyone to do it for me (that in itself serves no purpose) but merely a bit of help along with an explanation so I will not have to ask about the topic again and can do this myself instead of asking people.

9. that is so awesome thank you so much you just made things so much clearer! I actually understand it now and can complete my program Ur the best and thanks so much for the help! (I am now a better programmer than I was 10 minutes ago :P )

10. Ok I'm getting somewhere here, however, to make my code more efficient and better, if for example I have created a function (just a small bit of my program) how can I , without copying it out many times, make sure that when the userInput is multiplied by the multiplyBy value, every time this loops it will store the result of the subsequent operation in different variable names (e.g anagramToTest1,2,3,4 etc...)

Code:
```void multiplyNumber(int userInput)

while(multiplyBy<9)
{
int multiplyBy = 2;
userInput*multiplyBy = anagramToTest1;
multiplyBy++;

}```

Then edit your post if you still can, and make your code as readable as Post #3

12. Originally Posted by Salem
Then edit your post if you still can, and make your code as readable as Post #3
Sorry I wasn't aware of this practice

13. Originally Posted by alexbcg
Ok I'm getting somewhere here, however, to make my code more efficient and better, if for example I have created a function (just a small bit of my program) how can I , without copying it out many times, make sure that when the userInput is multiplied by the multiplyBy value, every time this loops it will store the result of the subsequent operation in different variable names (e.g anagramToTest1,2,3,4 etc...)

Code:
```void multiplyNumber(int userInput)

while(multiplyBy<9)
{
int multiplyBy = 2;
userInput*multiplyBy = anagramToTest1;
multiplyBy++;

}```
You could create an array and change your loop a bit:
Code:
```int anagramsToTest[7];
int i;

for(i = 0;i < 7;++i)
{
multiplyBy = i + 2;
...
}```
i would obviously become an index into the anagramsToTest array.

Your original loop had a bug in it that would cause the same anagram calculation every time. You had a multiplyBy variable that seemingly masked another multiplyBy variable, and that new variable was set to 2 on every iteration of the loop and then used in the calculation. Of course, you also had the lvalue on the right hand side of the assignment operator so you would have gotten a compile error anyway.