User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 423,808 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,684 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 158 | Replies: 2
Reply
Join Date: Nov 2007
Posts: 46
Reputation: manzoor is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
manzoor manzoor is offline Offline
Light Poster

separate integer into individual units

  #1  
May 12th, 2008
ok in what way do you separate the digits from a given int ??


like if the int is 987987

how do you separate them in to 9 8 7 9 8 7 ???

is there any function to do this ?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2008
Posts: 184
Reputation: Traicey is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 16
Traicey's Avatar
Traicey Traicey is offline Offline
Junior Poster

Re: separate integer into individual units

  #2  
May 12th, 2008
Here's one of the easiest way of doing it

  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <sstream>
  4.  
  5. using namespace std;
  6.  
  7. void separate(int n)
  8. {
  9. stringstream s;
  10. char c;
  11.  
  12. s << n;
  13.  
  14. while (s.get(c))
  15. cout << c << " "; //outputing the integer with the spaces
  16. }
  17.  
  18. void main()
  19. {
  20. int n;
  21.  
  22. cout << "enter number: ";
  23. cin >> n;
  24.  
  25. separate(n); // calling separate function
  26. cout << endl;
  27. }
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
Reply With Quote  
Join Date: Nov 2007
Posts: 46
Reputation: manzoor is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
manzoor manzoor is offline Offline
Light Poster

Re: separate integer into individual units

  #3  
May 12th, 2008
i know there are lot of ways but how to do it with integer division and modulus operator ?

sorry to mention that
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 2:53 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC