Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2004

    Unanswered: calculte squared digit length in c++

    hi, i am a beginner in c++.

    I plan to determine the squared digit length of an integer.
    You take an integer (e.g.29( and add up the squares of its digits. This will give u another integer. I want to repeat this process using loops until i end up with a 1 or a 4. the squared digit length is the number of times this process has to be repeated before it gets to 1 or 4.

    for example, if we start with 29, we get:
    2^2 + 9^2=85
    8^2 + 5^2=89
    8^2 + 9^2=145
    1^2 + 4^2 + 5^2=42
    4^2 + 2^2=20
    2^2 + 0^2=4

    this process shows that the squared digit length of 29 is 6.


    my problem is that i don't know how to take out digits in an integer.
    does anyone know the solution to the problem above?

    thanks alot

    deperate mel

  2. #2
    Join Date
    Feb 2004
    In front of the computer
    Provided Answers: 54
    You should really ask your teacher, but you'll eventually be interested in the modulo function and division by ten. Please see your teacher or their assistant for more details.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts