fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void multiply(int nr[], int x, int product[]) {
  5. int carry = 0;
  6. int numDigits = nr[0];
  7. product[0] = 0;
  8. for (int i = 1; i <= numDigits; ++i) {
  9. int nrDigit = nr[i] * x + carry;
  10. product[i] = nrDigit % 10;
  11. carry = nrDigit / 10;
  12. }
  13. int currentNum = numDigits + 1;
  14. if (carry > 0) {
  15. product[currentNum] = carry % 10;
  16. carry /= 10;
  17. ++currentNum;
  18. }
  19. }
  20.  
  21. int main() {
  22. int nr[] = {5, 1, 2, 2, 5, 8};
  23. int x = 3;
  24. int product[1000];
  25. multiply(nr, x, product);
  26. for (int i = product[0]; i >= 1; --i) {
  27. cout << product[i] << " ";
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty