Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int add_up (int *a, int** b, int num_elements);
- int main()
- {
- int orders[5] = {100, 220, 37, 16, 98};
- int *orders_sum = (int *)malloc(sizeof(int) * 5);
- if (orders_sum == NULL) {
- printf("Memory not allocated.\n");
- exit(0);
- }
- printf("Total orders is %d\n", add_up(orders, &orders_sum, 5));
- for (int i = 0; i < 5; ++i)
- {
- printf("sum of the elements at %d is %d\n", i, orders_sum[i]);
- }
- return 0;
- }
- int add_up (int *a, int** b, int num_elements)
- {
- int total = 0;
- for (int k = 0; k < num_elements; ++k)
- {
- total += a[k];
- }
- for (int i = 0; i < num_elements; ++i)
- {
- for (int k = num_elements - 1; i <= k; --k)
- {
- (*b)[i] += a[k];
- }
- }
- return (total);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement