using
System;
public
class
Node
{
public
int
data;
public
Node next;
}
public
class
GFG
{
public
static
void
Push(
ref
Node head_ref,
int
new_data)
{
Node new_node =
new
Node();
new_node.data = new_data;
new_node.next = head_ref;
head_ref = new_node;
}
public
static
int
DigitSum(
int
num)
{
int
sum = 0;
while
(num != 0)
{
sum += (num % 10);
num /= 10;
}
return
sum;
}
public
static
void
SumAndProductHelper(Node ptr,
ref
int
prod,
ref
int
sum)
{
if
(ptr ==
null
)
{
return
;
}
SumAndProductHelper(ptr.next,
ref
prod,
ref
sum);
if
((DigitSum(ptr.data) & 1) == 0)
{
prod *= ptr.data;
sum += ptr.data;
}
}
public
static
void
SumAndProduct(Node head_ref)
{
int
prod = 1;
int
sum = 0;
SumAndProductHelper(head_ref,
ref
prod,
ref
sum);
Console.WriteLine(
"Sum = "
+ sum);
Console.WriteLine(
"Product = "
+ prod);
}
public
static
void
Main(
string
[] args)
{
Node head =
null
;
Push(
ref
head, 13);
Push(
ref
head, 6);
Push(
ref
head, 8);
Push(
ref
head, 16);
Push(
ref
head, 15);
SumAndProduct(head);
}
}