P061.c (985B)
1 /* 2 * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 14 Dec 2025 3 * Repo: https://github.com/notamitgamer/bsc 4 * License: MIT 5 */ 6 7 /* Write a C program to find the sum of even elements in an array using a user defined function. 8 Define a functions int sumEven(int arr[], int n) that returns the sum of all even elements in the array. */ 9 10 #include <stdio.h> 11 12 void inputarr(int[], int); 13 int sumEven(int[], int); 14 15 int main() 16 { 17 int arr[20], n; 18 printf("Enter the n (Max: 20): "); 19 scanf("%d", &n); 20 inputarr(arr, n); 21 printf("\nSum of the even number in the array: %d", sumEven(arr, n)); 22 return 0; 23 } 24 25 void inputarr(int arr[], int n) 26 { 27 int i; 28 for (i = 0; i < n; i++) 29 { 30 printf("Enter element %d: ", i + 1); 31 scanf("%d", &arr[i]); 32 } 33 } 34 35 int sumEven(int arr[], int n) 36 { 37 int i, sum_even = 0; 38 for (i = 0; i < n; i++) 39 { 40 if (arr[i] % 2 == 0) 41 { 42 sum_even += arr[i]; 43 } 44 } 45 return sum_even; 46 }