Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

this question Design a program in C, using the method of call by reference, whic

ID: 3536178 • Letter: T

Question

this question

Design a program in C, using the method of call by reference, which will compute the equivalent resistance REQ to the M resistors R[0], R[ 1], R[2],.... R[M-l]1 connected in series where the number M of resistors is user-supplied. The resistors R[0], R[l], R[2],..., R[M-1] are actually equivalent resistors to a user-supplied number of resistors connected in parallel. Thus, R[0] = R[00] | | R[01] | | R[02] | | ...| | R[0(N0-1)], i.e., R[0] is the equivalent resistance to No resistors R[00], R[01], R[02],...,R[0(No-l)] connected in parallel, where the number No is user-supplied and the resistors values R[00], R[01], R[02],...,R[0(No-1)] are user-supplied. Similarly, for instance, R[3] = R[30] | | R[31] | | R[32]| | ... R[3(N3-1)], i.e., R[3] is the equivalent resistance to N3 resistors R[30], R[31], R[32],...,R[3(N3-1)] connected in parallel, where the number N3 is user-supplied and the resistors values R[30], R[31], R[32],...,R[3(N3-1)] are user-supplied.

Explanation / Answer

#include <stdio.h>

void compute_series(float R[], int size,float *output)
{
int i=0;
*output =0;
for(i=0; i<size; i++)
{
*output = *output + R[i];
}
}
void compute_parllel(int R[], int size,float *output)
{
int i=0;
float R_eq = 0;
for(i=0; i<size; i++)
{
R_eq = R_eq+1/(float) R[i];
// printf("%d %f",R[i],R_eq);
}
*output = 1/R_eq;
}

int main(void) {

int M,i=0;
int local,j=0;;
int R[20];
float par_out[20];
float series_out,parllel_out;
printf(" enter no of parllel circuits");
scanf("%d", &M);
for(i=0; i<M; i++)
{
printf(" enter no of parllel resistors in parllel circuit %d ", (i+1));
scanf("%d", &local);
for(j=0; j<local; j++)
{
scanf("%d", &R[j]);
}
compute_parllel(R,local,&parllel_out);
par_out[i] = parllel_out;
}
compute_series(par_out,M,&series_out);
printf(" equivalent series resistance is %f ", series_out);


return 0;
}