+ 1

My for loop is not working correctly. Please assist.

Hello everyone, I'm c++ beginner. I wrote This code which is meant to print a list of Automorphic numbers in the range of 1 to 1000 but I'm not getting the expected outcome. I have tried troubleshooting it myself but to no avail. I have a function that prints only automorphic number. The function works perfectly if I pass arguments to it one after the other, but when I used the for loop to pass a series of arguments in range of 1 to 1000 the outcome is not as expected. https://code.sololearn.com/c00OEdcB

18th Oct 2017, 10:28 PM
Temitayo Giwa
Temitayo Giwa - avatar
11 Answers
+ 1
what you think are automorphic numbers?
19th Oct 2017, 12:05 AM
Oma Falk
Oma Falk - avatar
19th Oct 2017, 6:46 AM
Siva Shankar
Siva Shankar - avatar
+ 1
I think I answered your question. The problem is memory limit, you can test it changing for limit from 1000 to 100 or you can run it in your computer with a c++ installer compiler
19th Oct 2017, 11:55 AM
Daniel
Daniel - avatar
0
https://code.sololearn.com/c00OEdcBErLR/?ref=app Could you share post for that challenge?
18th Oct 2017, 10:37 PM
Daniel
Daniel - avatar
0
Thanks... I have just done that
18th Oct 2017, 11:13 PM
Temitayo Giwa
Temitayo Giwa - avatar
0
what was the problem?
18th Oct 2017, 11:24 PM
Daniel
Daniel - avatar
0
If you read through my code, you will find a function called Autonum. What this function does is that whatever argument (number) u pass to it, it will print out that number only if it is an Automorphic number otherwise it will do nothing. But when I used the for loop to pass a series of arguments in range of 1 to 1000 to it, the list of Automorphic numbers in that range was not complete.
19th Oct 2017, 12:50 AM
Temitayo Giwa
Temitayo Giwa - avatar
0
I thougth you correct the problem. If you are talking about run the code in SL then the problem is for memory for the loop
19th Oct 2017, 1:52 AM
Daniel
Daniel - avatar
0
An automorphic number is a number whose square "ends" in the same digits as the number itself. For example, 5^2 = 25, 6^2 = 36, 76^2 = 5776, 376^2 = 141376, so 5, 6, 76 and 376 are all automorphic numbers. The answer should be the series 1,5,6,25,76,376,625. I think the problem is with the function and not for loop.Ur for loop is fine.
19th Oct 2017, 4:19 AM
Siva Shankar
Siva Shankar - avatar
0
Thanks for your answer. But can you please help me point out what might be wrong with my function Autonum as it performs the task if I pass it any value one at a time. For instance, I tested it by passing it values like 5, 6, 25, 76 which are known Automorphic numbers, and it printed them out(showing that it recognize automorphic numbers). I also tested it with numbers which are known to be non-Automorphic, like 8, 9, 10 and it was able to recognize that they are not. So I will really appreciate if someone can help me point out what is responsible for the malfunction of this function inside the for loop.
19th Oct 2017, 9:59 AM
Temitayo Giwa
Temitayo Giwa - avatar
0
The pow() function is usually used with float. Using int it returned max of 99. That's why ur code was not working.Define your own function instead of pow(). Aside from that u made way too many comparisons in AutoNum function which is causing too much time to execute.
19th Oct 2017, 10:58 AM
Siva Shankar
Siva Shankar - avatar