fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int divide(int a[], int b, int result[]) {
  5. int reminder = 0;
  6. int nrDigits = a[0];
  7. for (int i = nrDigits; i >= 1; --i) {
  8. int current = reminder * 10 + a[i];
  9. result[i] = current / b;
  10. reminder = current % b;
  11. }
  12. result[0] = nrDigits;
  13. return reminder;
  14. }
  15.  
  16. int main() {
  17. int a[] = {5, 1, 2, 2, 5,8}, b = 6;
  18. int product[10001] = {0};
  19. int reminder = divide(a, b, product);
  20. for (int i = product[0]; i >= 1; --i) {
  21. cout << product[i] << " ";
  22. }
  23. return 0;
  24. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
1 4 2 0 3