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 ?

Here's one of the easiest way of doing it

#include "stdafx.h"
#include <iostream>
#include <sstream>

using namespace std;

void separate(int n)
{
  stringstream s; 
  char c;

  s << n;

  while (s.get(c))  
    cout << c << " "; //outputing the integer with the spaces
}

void main()
{
  int n;

  cout << "enter number: ";
  cin >> n;  

  separate(n); // calling separate function
  cout << endl;
}

i know there are lot of ways but how to do it with integer division and modulus operator ?

sorry to mention that

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.