PROGRAM A:
Consider the problem of a user-specified number N of resistors with user-specified values of resistances connected in series across a battery whose terminal voltage VB is also user-specified. The N resistances are represented by a one-dimensional array R[N]. Design a program in C which will compute in an infinite loop the following:
- the equivalent resistance req to the N series-connected resistors,
- the current I in the circuit,
- the voltage array V[N] representing the voltage across the N resistors, and
- the power array P[N] representing the powers dissipated in the N resistors.
- The problem is to be solved using the method of call by value in which the calculation and outputting of req, I, V[N] and P[N] is to be performed from within a prototype function called "series" placed after the main function. Note that the formula for the voltage across resistance R[i] is V[i] = R[i] * I, and the power dissipated in resistance R[i] is P[i] = R[i] * I2.
When executed, the program will do the following in the indicated sequence:
1. Ask the user to type on the keyboard a value for the number N of resistors connected in series.
2. Ask the user to type on the keyboard the values R[0], R[1], R[2],.., R[N-1] of these N resistors.
3. Compute and display on the console the value of the equivalent resistance req to the N resistors connected in series which is given by the formula req = R[0] + R[1] + R[2] + ... + R[N-1.
4. Compute and display on the console the value of the current I in the circuit given by the formula I=VB/req.
5. Compute and display on the console the values of the elements of the voltage array V[N].
5. Compute and display on the console the values of the elements of the power array P[N].
6. Go back to step 1 and repeat the process ad infinitum.
PROGRAM B:
Modify PROGRAM A so that the N resistors are now connected in parallel across the battery. In the present program, the calculation is to be of the equivalent resistance req to the N resistors connected in parallel, the current I supplied by the battery, the current array I[N] representing the currents in the N resistors, and the power array P[N] representing the powers dissipated in the N resistors.