ARRAY-SUM OF EVEN NUMBERS
Problem Description
Write a program to find the sum of the even numbers present in an array using recursion.
Input and Output Format:
Refer sample input and output for formatting specifications.
CODING ARENA::
#include <stdio.h>
int main()
{
int a,i,sum=0;
scanf("%d",&a);
int arr[a];
for(i=0;i<a;i++)
{
scanf("%d",&arr[i]);
if(arr[i]%2==0)
sum+=arr[i];
}
printf("%d",sum);
return 0;
}
Test Case 1
Input (stdin)5
4 6 8 10 12
Expected Output
40
Test Case 2
Input (stdin)7
1 2 8 7 4 5 6
Expected Output
20
No comments:
Post a Comment