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

Design a program in C which will compute, using a one-dimensional array, the equ

ID: 2081706 • Letter: D

Question

Design a program in C which will compute, using a one-dimensional array, the equivalent resistance to a user-specified number N of resistors connected in series, with the values of these resistors also being user-specified. When executed, the program will do the following in sequence: 1. Ask the user to type on the keyboard 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. Display on the console a table consisting of two columns, the first one consisting of resistor numbers in the format R[0], R[1], R[2], .., R[N - 1], and the second column consisting of the user-inputted values of these resistors. 4. 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]. Your design is to be in the form of four separate programs: Program A: This design will perform a one-shot computation of req without utilizing a prototype function. Program B: This design will do the same thing as Program A but now the program design will utilize a prototype function called "series" which is placed after the main function and whose job is to compute the value of req from the resistance values passed from the main function and then to output to the console the value of req from within the prototype function. Program C: This program will be a modification of Program B in that it will place the prototype function repeat steps 1 - 4 in an infinite loop unless a value of 0 is inputted for N in which event the looping will be summarily terminated. Program D: This program will be a modification of Program C, with the prototype function series placed before the main function and the outputting of req to the console done from within the main function.

Explanation / Answer

Program A:

#include <stdio.h>
#include <stdlib.h>

int main()
{
int N,i;
// Getting the number of resistors
printf("Enter the number of resistors : ");
scanf("%d",&N);

double R[N],sum=0;

// Getting the values of resistors
for (i=0;i<N;i++)
{
printf(" Enter the value of resistor %d : ",i+1);
scanf("%lf",&R[i]);
}

// Displaying the values of resistors
printf(" Resistor Values ");
for (i=0;i<N;i++)
{
printf("R[%d] %lf ",i,R[i]);
sum += R[i]; // Calculating equivalent resistance
}
// Displaying the equivalent resistance
printf("Equivalent resistance req = %lf ",sum);
return 0;
}

Program B:

#include <stdio.h>
#include <stdlib.h>
void series(double arr[],int size);
int main()
{
int N,i;
// Getting the number of resistors
printf("Enter the number of resistors : ");
scanf("%d",&N);

double R[N];

// Getting the values of resistors
for (i=0;i<N;i++)
{
printf(" Enter the value of resistor %d : ",i+1);
scanf("%lf",&R[i]);
}
series(R,N);
return 0;
}
void series(double arr[],int size)
{
int i;
double sum = 0;
// Displaying the values of resistors
printf(" Resistor Values ");
for (i=0;i<size;i++)
{
printf("R[%d] %f ",i,arr[i]);
sum += arr[i]; // Calculating equivalent resistance
}
// Displaying the equivalent resistance
printf("Equivalent resistance req = %lf ",sum);
}

Program C:

#include <stdio.h>

#include <stdlib.h>
void series(double arr[],int size);
int main()
{
int N,i;
// Getting the number of resistors
printf("Enter the number of resistors : ");
scanf("%d",&N);
while(N)
{
double R[N];

// Getting the values of resistors
for (i=0;i<N;i++)
{
printf(" Enter the value of resistor %d : ",i+1);
scanf("%lf",&R[i]);
}
series(R,N);
printf(" Enter the number of resistors : ");
scanf("%d",&N);
}
return 0;
}
void series(double arr[],int size)
{
int i;
double sum = 0;
// Displaying the values of resistors
printf(" Resistor Values ");
for (i=0;i<size;i++)
{
printf("R[%d] %f ",i,arr[i]);
sum += arr[i]; // Calculating equivalent resistance
}
// Displaying the equivalent resistance
printf("Equivalent resistance req = %lf ",sum);
}

Program D

#include <stdio.h>

#include <stdlib.h>
double series(double arr[],int size)
{
int i;
double sum = 0;
// Displaying the values of resistors
printf(" Resistor Values ");
for (i=0;i<size;i++)
{
printf("R[%d] %f ",i,arr[i]);
sum += arr[i]; // Calculating equivalent resistance
}
return sum;
}
int main()
{
int N,i;
// Getting the number of resistors
printf("Enter the number of resistors : ");
scanf("%d",&N);
while(N)
{
double R[N],sum;

// Getting the values of resistors
for (i=0;i<N;i++)
{
printf(" Enter the value of resistor %d : ",i+1);
scanf("%lf",&R[i]);
}
sum = series(R,N);
// Displaying the equivalent resistance
printf("Equivalent resistance req = %lf ",sum);

printf(" Enter the number of resistors : ");
scanf("%d",&N);
}
return 0;
}

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