Plz help...number string!!

This is a discussion on Plz help...number string!! within the C++ Programming forums, part of the General Programming Boards category; Hi all, I have a number like 51634792 from which I want to fetch 1372. i.e other numbers are just ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    11

    Question Plz help...number string!!

    Hi all,

    I have a number like 51634792 from which I want to fetch 1372. i.e other numbers are just for padding. How can I achieve this in C++? The number is Integer type.

    Kindly help

    Symbee

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Well, you think about the math behind it, and we'll help you out with the C++ part.

    Hint: think about what you could do to isolate a digit from that number.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    11
    I have thought about devide and modulo method like if number is 12 then 12%10=2 and 12/10=1(only integer and not float) but I dont know about 8 digit number!! probably by resursion I can do! but as I m newbie, I dnt know how to achieve that

    Kindly help

    Best regards
    Symbee

  4. #4
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Well, not recursion necessarily, but certainly a loop:

    1234 % 10 = 4 <---
    1234 / 10 = 123

    123 % 10 = 3 <---
    123 / 10 = 12

    12 % 10 = 2 <---
    12 / 10 = 1

    1 % 10 = 1 <---
    1 / 10 = 0

    Note you can even continue the pattern, so you can program to extract enough digits to fit the largest possible ints, without a problem:

    0 % 10 = 0
    0 / 10 = 0
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  5. #5
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Recursion is a way of performing repetition, but there are also iterative 'loop' structures.

    http://www.cplusplus.com/doc/tutorial/control.html

    You got the gist of it. But try these operations on for size.

    1 % 10 = 1;
    1 / 10 = 0;

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    11
    Thanx all,

    Regards
    Symbee

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. Issue w/ Guess My Number Program
    By mkylman in forum C++ Programming
    Replies: 5
    Last Post: 08-23-2007, 01:31 AM
  3. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 02:40 AM
  4. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21