Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int mul(int a, int b)
- {
- return a * b;
- }
- int fold(int* array, int n, int *mul(int, int))
- {
- int result = *mul(array[0], array[1]);
- for (int i = 2; i < n; i++)
- result = *mul(result, array[i]);
- return result;
- }
- int main()
- {
- int* array;
- int n;
- printf("Enter the size of the array: ");
- scanf("%d", &n);
- array = (int*)malloc(n * sizeof(int*));
- for (int i = 0; i < n; i++)
- {
- printf("Enter array[%d]: ", i);
- scanf("%d", &array[i]);
- }
- printf("Original array: ");
- for (int i = 0; i < n; i++)
- printf("%d ", array[i]);
- printf("\nThe product of all array numbers: %d", fold(array, n, *mul));
- free(array);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment