Skip to content

Instantly share code, notes, and snippets.

@siddharthaborah
Last active February 16, 2024 15:41
Show Gist options
  • Save siddharthaborah/a7511c35d93eddf098f864d42d849be8 to your computer and use it in GitHub Desktop.
Save siddharthaborah/a7511c35d93eddf098f864d42d849be8 to your computer and use it in GitHub Desktop.
Sum of elements of array using function
#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;
}
@siddharthaborah
Copy link
Author

array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment