Thread: Adam number

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

    Join Date
    Jul 2013
    Posts
    26
    Rep Power
    0

    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
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,413
    Rep Power
    1871
    Is it too hard for you to type in "adam number algorithm" into google?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    103
    Rep Power
    3
    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.
  6. #4
  7. 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
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    103
    Rep Power
    3
    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.
  10. #6
  11. 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.
    I no longer wish to be associated with this site.
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    India
    Posts
    95
    Rep Power
    4
    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.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    26
    Rep Power
    0

    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:
  16. #9
  17. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,413
    Rep Power
    1871
    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
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    26
    Rep Power
    0

    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
  20. #11
  21. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,413
    Rep Power
    1871
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    26
    Rep Power
    0

    Adam number


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

IMN logo majestic logo threadwatch logo seochat tools logo