Write a program which multiplies an N digit number M by a 1 digit number d, where N could be large, e.g. 1000. The input will be given as follows. First, the user gives d, then N and then the digits of M, starting from the least significant to the most significant. The program must print out the digits of the product one at a time, from the least significant to the most significant.
Hint: Mimic the process of manual multiplication. Keep track of the current carry in a variable and update it as you go along.
#include <iostream>
using namespace std;
int main () {
// N digit number M and N could be large
int N;
// 1 digit number d
int d;
cout << "Enter 1 digit number: "; cin >> d;
cout << "Enter how many digits in M: (N = ) "; cin >> N;
// an array for digits of many
int Array[N];
cout << "Enter digits of M: " << endl;
for (int i = N - 1; i >= 0; i--) {
cin >> Array[i];
}
cout << "The shown of M is ";
for (int i = 0; i < N; i++) {
cout << Array[i];
}
cout << "\nAfter to multiple every digit to " << d << endl;
for (int i = 0; i < N; i++) {
Array[i] *= d;
cout << Array[i];
}
}
Comments
Leave a comment