# Need a little help with Cyclic Numbers Program

• 10-19-2005
SlyMaelstrom
Need a little help with Cyclic Numbers Program [FIXED/CLOSED]
** Edit, I think I got it fixed, now, thanks for reading **

First off, before I start. I am writing this program for a college class, there for I don't want any suggestions on how to write the program better, I'm only asking one specific question.
"Why is it stopping where it is?"
If you have a suggestion or answer that doesn't pertain to that question, then it's information I don't want to know. This is an assignment and I don't want anyone else doing the whole thing for me.

This objective of this assignment is to write a program to find all six digit cyclic numbers. If you don't know what a cyclic number is, it's a number that when multiplied by any number (in the case of the assignment, only through 6) will produce a number with the same six digits.

For example:

123456 * 2 = 253461
123456 * 3 = 365124
123456 * 4 = 451632
... and so on through six. These are not correct calculations, it's just an example.

Now that we've covered what cyclic numbers are, here is my program.

Code:

```#include <iostream.h> int main() {         long sixDigitNum = 100000;         long digitMutlip;         int digiValue[6][6];    // Array[mulitiplier][digit]         int numAppear[6][10];    // Array[mulitiplier][number]         int mult = 0;         int number = 0;                 cout << "Checking for Cyclic Numbers. Please Wait..." << endl;         while (sixDigitNum <= 166666) {             // Process 1: Parsing Digits              do {           digitMutlip = sixDigitNum * (mult + 1);                       digiValue[mult][5] = digitMutlip / 100000;           digiValue[mult][4] = (digitMutlip % 100000) / 10000;           digiValue[mult][3] = (digitMutlip % 10000) / 1000;           digiValue[mult][2] = (digitMutlip % 1000) / 100;           digiValue[mult][1] = (digitMutlip % 100) / 10;           digiValue[mult][0] = (digitMutlip % 10);                              mult++;                        } while (mult <= 5);     // End Process 1           mult = 0;       cout << "Parsed Digits" << endl;       cout << sixDigitNum << endl;           // Process 2: Totaling Number Appearence       do {           if (digiValue[mult][5] == number)               numAppear[mult][number] = numAppear[mult][number] + 1;           if (digiValue[mult][4] == number)               numAppear[mult][number] = numAppear[mult][number] + 1;           if (digiValue[mult][3] == number)               numAppear[mult][number] = numAppear[mult][number] + 1;           if (digiValue[mult][2] == number)               numAppear[mult][number] = numAppear[mult][number] + 1;           if (digiValue[mult][1] == number)               numAppear[mult][number] = numAppear[mult][number] + 1;           if (digiValue[mult][0] == number)               numAppear[mult][number] = numAppear[mult][number] + 1;                     if (number == 9) {               number = 0;               mult++;               }           else               number++;                } while (mult <= 5);            // End Process 2             mult = 0;       number = 0;       cout << "Totaled Appearences" << endl;           // Process 3: Comparing mults       do {           if (numAppear[mult][number] == numAppear[mult + 1][number] &&               numAppear[mult][number] == numAppear[mult + 2][number] &&               numAppear[mult][number] == numAppear[mult + 3][number] &&               numAppear[mult][number] == numAppear[mult + 4][number] &&               numAppear[mult][number] == numAppear[mult + 5][number] &&               number < 9)               number++;           else if (numAppear[mult][number] == numAppear[mult + 1][number] &&                     numAppear[mult][number] == numAppear[mult + 2][number] &&                     numAppear[mult][number] == numAppear[mult + 3][number] &&                     numAppear[mult][number] == numAppear[mult + 4][number] &&                     numAppear[mult][number] == numAppear[mult + 5][number] &&                     number == 9) {                     cout << "Found Cyclic Number: " << sixDigitNum << endl;                     number++;                     }           else               number = 10;       } while (number <= 9);     // End Process 3       cout << "Not Cyclic" << endl;                    sixDigitNum++;     }                           cin.get();                 return 0;         }```
There are some lines of code in there that were for debugging purposes only, so I can see what is going on. They aren't permemant.

Basically, what this code is doing is running through one number, then parsing the digits of the second number and stopping. Here is the output it's giving me.

Code:

```Checking for Cyclic Numbers. Please Wait... Parsed Digits 100000 Totaled Appearences Not Cyclic Parsed Digits 0```
Can anyone tell me why it's stopping at this point, and why sixDigitNum is coming out to 0 instead of 100001?

• 10-19-2005
SlyMaelstrom
Ok, I figured out a few things for you to consider. One, this program doesn't work properly. I inputted a cyclic number and it said it didn't tell me that it was cyclic, even though it is.

Second, I found out the final zero in the output is the last digit in the last six digit number.

For example, if the number is 100000, the digit is 0, if it's 104353, the digit is 3, and so on... why that is, I don't know.

Third, It's not actually going through the parse digits loop the second time around, it's skipping over it, which is awkward for a do...while loop.
• 10-19-2005
Rashakil Fol
Code:

`int mult = 0;`
Interestingly enough, this problem can be solved using an absurdly fast algorithm.
• 10-19-2005
SlyMaelstrom
If your talking about the second declaration of it, that's been changed, I just forgot to edit it in the post, thanks for noticing.