0

Can anyone explain the algorithm of the following C program?

#include <stdio.h> int add_up (int *a, int num_elements); int main() { int orders[5] = {100, 220, 37, 16, 98}; printf("Total orders is %d\n", add_up(orders, 5)); return 0; } int add_up (int *a, int num_elements) { int total = 0; int k; for (k = 0; k < num_elements; k++) { total += a[k]; } return (total); }

13th Mar 2020, 4:52 AM
Yash Chaudhari
Yash Chaudhari - avatar
1 Answer
+ 4
It calls a function which takes two arguments, i.e. A pointer of an array of integers, and the number of elements in that array. The function then adds up all the elements within an array, and returns the sum.
13th Mar 2020, 4:58 AM
Hatsy Rei
Hatsy Rei - avatar