# Multiply two numbers represented as linked lists into a third list in C++

C++Server Side ProgrammingProgramming

In this tutorial, we are going to write a program that multiplies two numbers represented as linked list.

Let's see the steps to solve the problem.

• Initialise the two linked lists.

• Iterate over the two linked lists and generate two numbers.

• Multiply the resultant numbers and store the result in a variable.

• Create a new list with the result.

## Example

Let's see the code.

Live Demo

#include <bits/stdc++.h>
using namespace std;
struct Node {
int data;
struct Node* next;
};
struct Node* newNode = new Node;
newNode->data = new_data;
}
int _1 = 0, _2 = 0;
_1 = _1 * 10 + firstHead->data;
}
_2 = _2 * 10 + secondHead->data;
}
}
int result = _1 * _2;
while (result) {
result /= 10;
}
}
while(node != NULL) {
cout << node->data << "->";
node = node->next;
}
cout << "NULL" &l<t; endl;
}
int main(void) {
return 0;
}

## Output

If you run the above code, then you will get the following result.

3->2->1->NULL
2->1->NULL
6->7->4->1->NULL

## Conclusion

If you have any queries in the tutorial, mention them in the comment section.

Published on 03-Jul-2021 04:37:17