:: [intv] changing bases using stack. ::
HOME


[Date Prev][Date Next][Date Index]

[intv] changing bases using stack.


//Problem: Conversion to any bases using stack.
//Save as:

#include <iostream>
#include "stack.h"

using namespace std;

int main(){
  stack S;
  int test = 30;
  int B = 2;

  while(test > 0){
    S.push(test % B);
    test = test/B; //integer division.
  }

  while(!S.isEmpty()){
    cout << S.pop() << " ";
  }
  cout << endl;

}


Comments and corrections are appreciated and can be sent to papers@mia.ece.uic.edu. Click here for ©opyright information.