C programing
Write a function that takes an array of integers and applies
another function (f(x)= 3x+4) on each element and then stores the
result in another array and finally return it once it is done.
#include <stdio.h> #include <stdlib.h> int *modify_array(int *arr, int size); int main() { int arr[] = {4, 9, 1, 2, 5}, size = 5, i; int *result = modify_array(arr, size); for (i = 0; i < size; ++i) { printf("%d ", arr[i]); } printf("\n"); for (i = 0; i < size; ++i) { printf("%d ", result[i]); } printf("\n"); free(result); return 0; } int *modify_array(int *arr, int size) { int *result = (int *) malloc(sizeof(int) * size), i; for (i = 0; i < size; ++i) { result[i] = 3 * arr[i] + 4; } return result; }
Get Answers For Free
Most questions answered within 1 hours.