Skip to main content

Section 18.8 Practice Modifying Arrays with Functions

Activity 18.3.

Write a function enterValues() in which you ask the user to enter values to be stored in the array that is passed into the function. You can assume that the constant N holds the size of the array. Call your function from within main() with array as the argument.

Compile and run the code below in your own C environment.

#define N 10
#include <stdio.h>

/* function prototype here */

int main(void) {
    int array[N];
    int i;
    
    for (i=0; i<N; i++) {
        array[i] = 0;
    }
    printf("Array elements before function call: \n");
    for (i=0; i<N; i++) {
        printf("%d  ", array[i]);
    }
    printf("\n");
    
    /* function call here */
    
    printf("Array elements after function call: \n");
    for (i=0; i<N; i++) {
        printf("%d  ", array[i]);
    }
    printf("\n");
    
    return 0;
}

void enterValues(/*complete this part */) {
    /* function body here */
}