/* * Program to experiment with array access * (example of for loops also). */ #include #define ARRAY_SIZE 10 /* * second parameter is size of array -- could just use ARRAY_SIZE but * this way is more general */ void print_array(int nums[], int size) { printf("\n"); for (int i = 0; i < size; ++i) { printf("%d\n", nums[i]); } printf("\n"); } int main(void) { int nums[ARRAY_SIZE]; for (int i = 0; i < ARRAY_SIZE; ++i) { nums[i] = i+1; } print_array(nums, ARRAY_SIZE); printf("enter an index, ideally between 0 and %d\n", ARRAY_SIZE-1); int index; if (scanf("%d", &index) == 1) { nums[index] = -1; print_array(nums, ARRAY_SIZE); } else { printf("not an integer value\n"); } printf("enter a count, ideally between 0 and %d\n", ARRAY_SIZE); int count; if (scanf("%d", &count) == 1) { print_array(nums, count); } else { printf("not an integer value\n"); } return 0; }