July 24th, 2013, 12:06 PM

Adam number
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
July 24th, 2013, 03:23 PM

Is it too hard for you to type in "adam number algorithm" into google?
July 24th, 2013, 05:39 PM

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.
July 24th, 2013, 09:37 PM

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
July 24th, 2013, 09:40 PM

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 25th, 2013 at 12:44 AM.
July 24th, 2013, 10:05 PM

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.
I no longer wish to be associated with this site.
July 25th, 2013, 12:47 AM

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.
July 27th, 2013, 11:59 PM

Adam Number
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;
}
void Adam()
{ 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[]) {
Adam();
getch();
return 0;
}
:tbulb:
July 28th, 2013, 01:24 AM

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.
Learn to INDENT YOUR CODE
July 28th, 2013, 01:54 AM

Adam number
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
July 28th, 2013, 02:58 AM

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;
}
void Adam()
{
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[])
{
Adam();
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.
July 28th, 2013, 06:48 AM

Adam number
Thank you for your help. I Will then try to make the codes more user readable :cool: