Last active
February 16, 2024 15:41
-
-
Save siddharthaborah/a7511c35d93eddf098f864d42d849be8 to your computer and use it in GitHub Desktop.
Sum of elements of array using function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int sumOfArray(int arr[], int n); | |
int main(){ | |
int arr[10],i, n, sumOf; | |
printf("Enter the number of element: "); | |
scanf("%d",&n); | |
printf("Enter the elements of array: "); | |
for(i=0; i< n; i++){ | |
scanf("%d", &arr[i]); | |
} | |
sumOf = sumOfArray(arr, n); | |
printf("Sum of array: %d", sumOf); | |
return 0; | |
} | |
int sumOfArray(int arr[], int n){ | |
int i, sum = 0; | |
for (i=0; i<n; i++){ | |
sum = sum + arr[i]; | |
} | |
return sum; | |
} |
Author
siddharthaborah
commented
Jan 18, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment