Question
Write a program in C that copies every third element in an input array to an output array and discards all the other values. The
Write a program in C that copies every third element in an input array to an output array and discards all the other values. The program should include the following function: void decimate_by3(int a1[], int n, int a2[])T he function copies every third element in an input array a1[] of length n to an output array a2[]
and discards all the other values. (Hint: you might need the modulus (reminder) operator %)
1) read the numbers in the array, for example, 3 6 8 9.
2)Assume the input array has three or more elements.
3)In the main function, declare the input array after reading in the number of element of
the array, then read in the elements, then calculate the length of the output array, and
declare the output array, then call the decimate_by3 function.The main function should
display the output array.
Example input/output #1:
Enter
the length of the array: 8
Enter the elements of the array: 3 4 7 14 9 12 8 2
Output:3 14 8
Example input/output #2:
Enter
the length of the array: 6
Enter the elements of the array: 3 4 7 14 9 12
Output: 3 14
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started