If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > calculte squared digit length in c++

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-09-04, 01:31
mel8533 mel8533 is offline
Registered User
 
Join Date: Apr 2004
Posts: 1
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
Reply With Quote
  #2 (permalink)  
Old 04-09-04, 08:48
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
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.

-PatP
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On