#include <bits/stdc++.h>
using
namespace
std;
struct
Node {
int
data;
struct
Node* next;
};
int
digitSum(
int
num)
{
int
sum = 0;
while
(num) {
sum += (num % 10);
num /= 10;
}
return
sum;
}
void
SumProduct(
struct
Node* head,
int
key)
{
struct
Node* current = head;
int
sum = 0, product = 1;
if
(head == NULL) {
printf
(
"\nList is empty\n"
);
return
;
}
else
{
do
{
if
(!(digitSum(current->data)
& 1))
{
sum += current->data;
product *= current->data;
}
current = current->next;
}
while
(current != head);
}
cout <<
"Sum = "
<< sum
<<
", Product = "
<< product;
}
void
DisplayList(
struct
Node* head)
{
struct
Node* current = head;
if
(head == NULL)
{
printf
(
"\nList is empty\n"
);
return
;
}
else
{
do
{
printf
(
"%d "
, current->data);
current = current->next;
}
while
(current != head);
}
}
void
InsertNode(
struct
Node** head,
int
data)
{
struct
Node* current = *head;
struct
Node* newNode =
new
Node;
if
(!newNode) {
printf
(
"\nMemory Error\n"
);
return
;
}
newNode->data = data;
if
(*head == NULL) {
newNode->next = newNode;
*head = newNode;
return
;
}
else
{
while
(current->next != *head)
{
current = current->next;
}
newNode->next = *head;
current->next = newNode;
}
}
int
main()
{
struct
Node* head = NULL;
InsertNode(&head, 13);
InsertNode(&head, 6);
InsertNode(&head, 8);
InsertNode(&head, 15);
InsertNode(&head, 16);
cout <<
"Initial List: "
;
DisplayList(head);
cout << endl;
SumProduct(head, 11);
return
0;
}