Given a singly circular linked list. The task is to find the sum and product of nodes which are divisible by K of the given linked list.
Input : List = 5->6->7->8->9->10->11->11 K = 11 Output : Sum = 22, Product = 121 Input : List = 15->7->3->9->11->5 K = 5 Output : Product = 75, Sum = 20
- Initialize a pointer current with the head of the circular linked list and a sum variable sum with 0 and a product variable product with 1.
- Start traversing the linked list using a do while loop until all the nodes get traversed.
- If current node data is divisible by given key.
- Add the value of current node to the sum i.e. sum = sum + current -> data.
- Multiply the value of current node to the product i.e. product = product * current -> data.
- Increment the pointer to the next node of linked list i.e. temp = temp -> next.
- Print the sum and product.
Below is the implementation of the above approach:
Initial List: 5 6 7 8 9 10 11 11 Sum = 22, Product = 121
- Sum and Product of the nodes of a Singly Linked List which are divisible by K
- Delete all Prime Nodes from a Circular Singly Linked List
- Product of the nodes of a Singly Linked List
- Sum and Product of all Prime Nodes of a Singly Linked List
- Product of all nodes in a doubly linked list divisible by a given number K
- Circular Singly Linked List | Insertion
- Convert singly linked list into circular linked list
- Find minimum and maximum elements in singly Circular Linked List
- Splitting starting N nodes into new Circular Linked List while preserving the old nodes
- Sum of the nodes of a Singly Linked List
- Alternate Odd and Even Nodes in a Singly Linked List
- Delete all Non-Prime Nodes from a Singly Linked List
- Reverse alternate K nodes in a Singly Linked List
- Delete all Prime Nodes from a Singly Linked List
- Find the common nodes in two singly linked list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.