Write a program to find the sum of array elements
int main()
{
int sum;
int i, n;
int array[] = {1, 3, 5, 6, 9, 11, 5, 2, 1, 21, 23, 25, 3, 5, 7, 9, 11, 13, 26, 28};
n = sizeof(array)/sizeof(array[0]);
// if enter the array manually
//
// printf("Enter N: ");
// scanf("%d", &n);
// int array[n];
// printf("Enter array: \n");
// for (i = 0; i < n; i++)
// scanf("%d", &array[i]);
sum = 0;
printf("\nArray:\n");
for(i=1; i < n; i++)
{
printf("%d ", array[i]);
sum = sum + array[i];
}
printf("\n\nSum of array elements: %d ", sum);
return 0;
}
Comments
Leave a comment