1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2013
Posts
26
Rep Power
0

hi.i want to printout the adam no. from 1 to 100. I dont wish to have any source code but i need some idea ,like algorithm,so that i can try it my self
2. Is it too hard for you to type in "adam number algorithm" into google?
3. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2012
Posts
103
Rep Power
4
Instead of asking for the algorithm you should be asking yourself what an Atom number is. How do you determine if a number is an atom number?

I didn't know the answer to either of these questions. I used Google as a resource and read about atom numbers. I am now able to answer these questions. You can do it too!

Once you have done your research and if you still have questions then post back and I would be happy to help.
4. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2013
Posts
26
Rep Power
0
i think you have misunderstood my question.it is adam no. And it is a number that has the special property that the square of the reverse of a number is reverse of the square of the number.ex:12^2 =144 and 21^2=441 . The problem is that i dont know to reverse the number
5. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2012
Posts
103
Rep Power
4
jwdonahue provides some good advice for reversing a number in his post below mine. As he said, the key to reversing a number is representing a number as a String. You could also do it with Binary arithmetic, but that's harder to read.
Last edited by Cameron0960; July 24th, 2013 at 11:44 PM.
6. No Profile Picture
Contributing User
Devshed Loyal (3000 - 3499 posts)

Join Date
May 2004
Posts
3,417
Rep Power
887
So what is a number? Think about it a bit. In C, there's integers and there's strings of decimal digits. There's functions available to convert from int to string and back again. Has your instructor covered those yet? Reversing a string is a trivial exercise. I'll let you work the rest out for yourself.
7. Originally Posted by yashwanth.c.b
i think you have misunderstood my question.it is adam no. And it is a number that has the special property that the square of the reverse of a number is reverse of the square of the number.ex:12^2 =144 and 21^2=441 . The problem is that i dont know to reverse the number
then you should learn how to reverse the number.
after that logic of adam's number is easy.
8. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2013
Posts
26
Rep Power
0

Hi I have successfully found the way to print the Adam number.Thanks for your help.
Code:
```// Adam Number.cpp : Defines the entry point for the console application. //
/* 12^2=144  21^2=441
count from 10 to 100
square it one by one
and reverse it square again
if the square and reverse of the square are equal
print it
else continue with the next no */
#include "stdafx.h"
using namespace std;
int Square(int squarenum)
{ 	int square=squarenum*squarenum;
return square;
}
int Reverse(int reversenum)
{
int reverse=0;
while (reversenum != 0)
{
reverse = reverse * 10;
reverse = reverse + reversenum%10;
reversenum = reversenum/10;
}
return reverse;
}
{ 	for(int number=11;number<100;number++)
{
int squarenumber=Square(number);
int reverseanumber=Reverse(number);
int squareanumber=Square(reverseanumber);
int reverseagain=Reverse(squareanumber); 			if(reverseagain==squarenumber) 			{
cout<<number<<"\n";
}
else{}
}
}
int _tmain(int argc, _TCHAR* argv[]) {
getch();
return 0;
}```
:tbulb:
9. Great, all you need now do is work on the presentation of your code so other people might be able to read more than a few lines before deciding that there are much less painful things to do in life.

10. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2013
Posts
26
Rep Power
0

Thank You.But I don't know about Presentation of Code.
You mean That I should leave proper space in between the statements or do you mean that is should create user readable variables and insert comments where ever necessary?
Can you help me in this! :o
11. Indented code would look something like this.
Code:
```// Adam Number.cpp : Defines the entry point for the console application. //
/* 12^2=144  21^2=441
count from 10 to 100
square it one by one
and reverse it square again
if the square and reverse of the square are equal
print it
else continue with the next no */
#include "stdafx.h"
using namespace std;

int Square(int squarenum)
{
int square = squarenum * squarenum;
return square;
}

int Reverse(int reversenum)
{
int reverse = 0;
while (reversenum != 0) {
reverse = reverse * 10;
reverse = reverse + reversenum % 10;
reversenum = reversenum / 10;
}
return reverse;
}

{
for (int number = 11; number < 100; number++) {
int squarenumber = Square(number);
int reverseanumber = Reverse(number);
int squareanumber = Square(reverseanumber);
int reverseagain = Reverse(squareanumber);
if (reverseagain == squarenumber) {
cout << number << "\n";
} else {
}
}
}

int _tmain(int argc, _TCHAR * argv[])
{
getch();
return 0;
}```
Most code editors and IDEs have both
- an auto indent feature to keep things tidy as you type
- an indent tool to fix indentation if you import something which isn't indented.

For example, I typed (on Linux)
\$ indent -kr -nut -ts2 -i2 -l100 foo.c
to fix your code, and the result is posted above.
12. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2013
Posts
26
Rep Power
0