fork download
  1. #include <iostream>
  2.  
  3.  
  4. int i_pow( int number , const int n );
  5.  
  6. int main()
  7. {
  8. const int number = 3456;
  9. int digit = 0 , size = 0 , temp = number , power = 0;
  10.  
  11. while( temp > 0 )
  12. {
  13. ++size;
  14. temp /= 10;
  15. }
  16.  
  17. temp = number;
  18. for( int i = 0; i < size; ++i )
  19. {
  20. power = i_pow( 10 , size - 1 - i );
  21. digit = temp / power ;
  22. temp -= power * digit;
  23.  
  24. std::cout << "Digit " << i << " = " << digit << std::endl;
  25. }
  26. }
  27.  
  28. int i_pow( int number , const int n )
  29. {
  30. if( n > 0 ) return( number * i_pow( number , n - 1 ) );
  31. return( 1 );
  32. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Digit 0 = 3
Digit 1 = 4
Digit 2 = 5
Digit 3 = 6