Design a program in C,using the method of call by reference, which will compute
ID: 1811787 • Letter: D
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-1] , connected in series where the number M of resistors is user-supplied. The resistors R[0],R[1],R[2]...,R[M-1] are actually equivalent resistors to R[0]=R[00] || R[01] || R[02] ||...|| R[0(No-1)].
+R[0] is the equivalent resistance to No resistors R[00],R[01],R[02],....,R[0(No-1) connected in parallel ,where the number No is user-supplied and the resistor values R[00],R[01],R[02],....,R[0(No-1) are all user-supplied. Similarlly, for instance R[3]=R[30] || R[31] || R[32] ||...|| R[3(N3-1)]. 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 all user supplied.
Explanation / Answer
#include <stdio.h>
void compute_series(int 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 R[10];
float series_out,parllel_out;
printf("enter no of resistors");
scanf("%d", &M);
for(i=0; i<M; i++)
scanf("%d", &R[i]);
compute_series(R,M,&series_out);
compute_parllel(R,M,&parllel_out);
printf(" equivalent series resistance is %f, equivalent parllel resistance is %f ", series_out,parllel_out);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.