Question
Create a C source code file named lab6.c that implements the following features. This is a detailed and possibly confusing specification. Implement this program in
Create a C source code file named lab6.c that implements the following features. This is a detailed and possibly confusing specification. Implement this program in stages using stepwise refinement to ensure that it will compile and run as you go. This makes it much easier to debug and understand.
you will need to use printf() to format and print program results
define a symbolic constant macro named SIZE and make it equivalent to the value 20
implement a main() function that returns an integer and does not have any parameters
add the following variables to the function main()
declare and define two integer variables named i and j using a single C statement
in this same statement initialize j to zero (0)
add the following array variables to the function main()
declare and define an integer array named a of SIZE elements
declare, define, and initialize to values of zero (0), an integer array named b of SIZE elements
declare, define, and initialize to values of zero (0.0) a double array named ratio of SIZE elements
HINT: you are to initialize arrays using the array declaration statement and a single value
add the following for-loop to the function main()
use the variable i to subscript the array a from its first element to its last element
set each element of a to the element's subscript value HINT: the value of i
add the following for-loop to the function main()
use the variables i and j to subscript the array a and b respectively
set each element of b to the element value in a at the opposite corresponding end of the array
HINT: vary i from 0 to SIZE and at the same time vary j from SIZE to 0
HINT: this allows the statement b[j] = a[i]; to make sense
add the following for-loop to the function main()
use the variable i to subscript arrays a and b and ratio from the first to the last element
value each element in ratio using the ratio of the corresponding elements in a and b
HINT: to divide a[i] by b[i] resulting in a double value cast the divisor to a double
HINT: ratio[i] = a[i] / (double) b[i];
add the following for-loop to the function main()
use the variable i to subscript array ratio from its first element to its last element
use printf() with the following format specifier string to print each element of array ratio
HINT: "ratio[%d] = %f "
Change the macro value defined for SIZE to 10 then compile and run your program again
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