C programing
Write a function that takes in an integer as input and returns an
integer array of zeros.
#include <stdio.h> #include <stdlib.h> int *generate_array(int size); int main() { int n, i, *arr; printf("Enter size of array: "); scanf("%d", &n); arr = generate_array(n); for (i = 0; i < 10; ++i) { printf("%d ", arr[i]); } printf("\n"); free(arr); return 0; } int *generate_array(int size) { int *arr = (int *) malloc(sizeof(int) * size), i; for (i = 0; i < size; ++i) { arr[i] = 0; } return arr; }
Get Answers For Free
Most questions answered within 1 hours.