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