Print Sum of Even Number Using Recursion

Write a C program to print sum of Even Number in Array using Recursion
 
#include<stdio.h>
void SumOfEven(int a[ ] , int num , int sum);
main()
{
  Int i, a[100], num, sum=0;
  printf(“Enter number of Array Elementsn”);
  scanf(“%d” , &num);
  printf(“Enter Array Elementsn”);
  for(i=0;i<num;i++)
   {
scanf(“%d”,&a[i]);
}
SumOfEven(a,num-1,sum);
}
 void SumOfEven(int a[ ], int num, int sum)
{
  if(num>=0)
 {
  if((a[num])%2==0)
   {
sum+=(a,num-1,sum);
}
sumOfEven(a,num-1,sum);
   }
  else
   {
printf(“Sum=%dn”,sum);
return;
   }
}
Output
Enter number of Array Elements
7
Enter Array Elements
3
18
11
16
13
39
32
Sum=66
C Program For Selection Sort: Click Here
C Program For Binary Search and Bubble Sort: Click Here

C Program Sum of even number using recursion

Leave a Comment

error: Content is protected !!