/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
typedef struct node
{
int val;
struct node *next;
} node_t;
int numberOfEvenElements(node_t *node)
{
if (node == NULL)
{
return 0;
}
else return (node->val != 0 && node->val % 2 == 0) ? 1 + numberOfEvenElements(node->next) : numberOfEvenElements(node->next) ;
}
int main()
{
node_t *head = malloc(sizeof(node_t));
head->val = 2;
head->next = malloc(sizeof(node_t));
head->next->val = 4;
head->next->next = malloc(sizeof(node_t));
head->next->next->val = 6;
printf("even count = %d", numberOfEvenElements(head));
return 0;
}