Problem Statement: Calculate the sum of the array elements
/*C program to print the sum of array elements*/ #include <stdio.h> int main() { int n; printf("Enter the number of element\t"); scanf("%d", &n); int array[n], sum = 0; printf("Enter array elements\n"); for (int i = 0; i < n; i++) scanf("%d", &array[i]); for (int i = 0; i < n; i++) sum = sum + array[i]; printf("Sum of array elemsnts is %d", sum); return 0; }
$gcc array.c $ ./a.out Enter the number of element 5 Enter array elements 1 2 3 4 5 Sum of array elemsnts is 15$ |
Time complexity:O(n)
also see
C Programming language |
Go Programming language |
Linked List | Array |
Stack | Queue |
Puzzle | Reasoning |
Aptitude | HTML |