Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
list multiply
//Title of this code #include <iostream> using namespace std; struct node { int data; node* next; node(int d, node* n): data(d), next(n) {} }; /* 1 -> 7 -> 3 -> NULL - 378 9 -> 8 -> NULL - 89 */ node* multiply(node* head1, node* head2) { int carry = 0; node* res; node* num1 = head1; while (num1) { node* num2 = head2; while (num2) { int num = carry + (num1->data * num2->data); if (num > 9) { carry = num / 10; num = num % 10; } else carry = 0; cout << num << " "; //if (num){} num2 = num2->next; } num1 = num1->next; cout << endl; } return NULL; } int length(node* head) { int i = 0; while (head) { ++i; head = head->next; } return i; } int main() { node* num1 = new node(1, new node(2, new node(3, NULL))); node* num2 = new node(1, new node(1, NULL)); multiply(num2, num1); std::cout << "Hello, world!\n"; }
run
|
edit
|
history
|
help
0
c++ eval - double numbers v1.0
empty base bug
Hello World
ntohl
RecursiveDivide
Strings
#32
Struct packing
1
problem_binary_4