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

The present quiz is concerned with making calculations on the circuit shown belo

ID: 3839107 • Letter: T

Question

The present quiz is concerned with making calculations on the circuit shown below which consists of: i) an ideal battery with user-supplied terminal voltage and ii) a user-supplied number m of branches of resistors which are connected in series within each branch, with these branches connected in parallel across each other, and with each branch consisting of a variable user-supplied number n of resistors and user-supplied values of the resistors. Design two programs in C, one using the method of call by value and the other using the method of call by reference, which will perform the following computations: i) the equivalent resistance R_eq seen by the battery, and ii) the one-dimensional array whose elements are the currents in the m branches. For sample output, use the following values for the circuit elements:

Explanation / Answer

//Call by value

#include <stdio.h>
#define max_branches 100       //Assuming upper limit of 100 branches, you can change it as required
#define max_resistors 100   //Assuming upper limit of 100 required, you can change it as required

float reciprocal ( float resistance_reciprocal_val); //This function returns the reciprocal of give value

int main() {
   int m;   //number of branches
   int n;   //number of resistors in each branch
   float circuit[max_branches][max_resistors];
   float resistance_each_branch[max_branches];
   float current_each_branch[max_branches];
   float net_resistance, resistance_reciprocal;
   int i,j;   //reference variable for looping
   float Req = 0.0;   //Equivalent resistance
   float voltage;   //Voltage that shall be supplied
  
   printf(" Enter the number of branches: ");
   scanf("%d", &m); //Accept number of branches in circuit
  
   printf(" Enter the voltage supplied: ");
   scanf("%f",&voltage);   //Accept voltage value
  
   for(i=0; i<m; i++)
   {  
       printf(" Enter the number of resistors in branch %d: ",i+1);
       scanf("%d",&n);
       for(j=0; j<n; j++)
       {
           printf(" Enter resistance value of Branch %d Resistor %d",i+1,j+1);   //Accept each resistor value
           scanf("%f",&circuit[i][j]);
           resistance_each_branch[i] += circuit[i][j]; //Net resistance of each branch is caluclated by adding, as resistors are connected in series
       }
       current_each_branch[i] = voltage/resistance_each_branch[i]; //Current = Voltage/resistance
       printf(" Current in branch %d is %f Amps.",i+1,current_each_branch[i]);
       resistance_reciprocal += 1/(resistance_each_branch[i]);   //addidng reciprocals of net resistant of each branch
       n=0;
   }
  
net_resistance = reciprocal(resistance_reciprocal); // actual net resistance is calulated as reciprocal of sum of 1/Resistance in each branch
   //Call by value and the parameters passed here are called formal parameters
  
  
   printf(" Net Resistance in the circuit is %f Ohms.",net_resistance);
  

   return 0;
}

float reciprocal ( float resistance_reciprocal_val)
{
return (1/resistance_reciprocal_val);
}

==========================================================================================================================================================================

//Call by reference

#include <stdio.h>
#define max_branches 100       //Assuming upper limit of 100 branches, you can change it as required
#define max_resistors 100   //Assuming upper limit of 100 required, you can change it as required

void reciprocal ( float *resistance_reciprocal_val); //This function returns the reciprocal of give value

int main() {
   int m;   //number of branches
   int n;   //number of resistors in each branch
   float circuit[max_branches][max_resistors];
   float resistance_each_branch[max_branches];
   float current_each_branch[max_branches];
   float resistance_reciprocal;
   int i,j;   //reference variable for looping
   float Req = 0.0;   //Equivalent resistance
   float voltage;   //Voltage that shall be supplied
  
   printf(" Enter the number of branches: ");
   scanf("%d", &m); //Accept number of branches in circuit
  
   printf(" Enter the voltage supplied: ");
   scanf("%f",&voltage);   //Accept voltage value
  
   for(i=0; i<m; i++)
   {  
       printf(" Enter the number of resistors in branch %d: ",i+1);
       scanf("%d",&n);
       for(j=0; j<n; j++)
       {
           printf(" Enter resistance value of Branch %d Resistor %d",i+1,j+1);   //Accept each resistor value
           scanf("%f",&circuit[i][j]);
           resistance_each_branch[i] += circuit[i][j]; //Net resistance of each branch is caluclated by adding, as resistors are connected in series
       }
       current_each_branch[i] = voltage/resistance_each_branch[i]; //Current = Voltage/resistance
       printf(" Current in branch %d is %f Amps.",i+1,current_each_branch[i]);
       resistance_reciprocal += 1/(resistance_each_branch[i]);   //addidng reciprocals of net resistant of each branch
       n=0;
   }
  
   reciprocal(&resistance_reciprocal); // actual net resistance is calulated as reciprocal of sum of 1/Resistance in each branch
   //Call by reference and the parameters passed here are called actual parameters
  
  
   printf(" Net Resistance in the circuit is %f Ohms.",resistance_reciprocal);
  

   return 0;
}

void reciprocal ( float *resistance_reciprocal_val)
{
*resistance_reciprocal_val = (1 / (*resistance_reciprocal_val));
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote