Advertisement
AntonioVillanueva

Separa INT segun la posicion unidad,decena,centa

Mar 12th, 2016
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. //La posicion determina el divisor
  6.  
  7. int separa( int num,int pos){
  8.     int p=pow(10,pos); 
  9.     num=(num /p)%10;
  10.     return num;
  11. }
  12.  
  13. int main (){
  14.     int num,pos;
  15.     while (true){//Bucle continuo para test de la funcion separa
  16.         cout<<" numero ";cin>>num;
  17. //      if (num==0){break;}//Con 0 se sale
  18.         cout<<" posicion ";cin>>pos;   
  19. //      cout <<separa (num*10,pos)<<endl;//Para empezar desde 1
  20.         cout <<separa (num,pos)<<endl;
  21.     }
  22. return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement