Answer to Question #161053 in C++ for Naveen K Madival

Question #161053

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.



1
Expert's answer
2021-02-05T13:31:33-0500
#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];
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog