Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct node
- {
- int number;
- node *next;
- };
- void push(node **top, int n)
- {
- node *ptr = new node;
- ptr->number = n;
- if (top == NULL)
- *top = ptr;
- else
- {
- ptr->next = *top;
- *top = ptr;
- }
- }
- int mult(node *top)
- {
- node *ptr = top;
- int res = 1;
- while (ptr)
- {
- res = res * ptr->number;
- ptr = ptr->next;
- }
- return res;
- }
- void print(node *top)
- {
- node *ptr = top;
- while (ptr)
- {
- cout << ptr->number << " ";
- ptr = ptr->next;
- }
- cout << endl;
- }
- int main()
- {
- node *top = NULL;
- int elem_quan;
- int enter_n;
- cout << "enter number of elems: ";
- cin >> elem_quan;
- for (int i = 0; i < elem_quan; i++)
- {
- cin >> enter_n;
- push(&top, enter_n);
- }
- print(top);
- push(&top, mult(top));
- print(top);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement