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

Homework 10 The present homework is concerned with the use of pointers in comput

ID: 3762045 • Letter: H

Question

Homework 10 The present homework is concerned with the use of pointers in computing the equivalent resistance to resistors connected in series. The number of resistors N connected in series and their resistance values R[0], R[1], R[N-11 are user-supplied. You are to design two programs both of which use the two prototype functions called input and series. In both programs, the inputting of the number of resistors N and the one-dimensional array elements R[0], R[1], R[N-11 is done within the input prototype function. In both programs, these values in turn are passed to the series prototype function, where the computation of the equivalent resistance Req is performed. The difference between the two programs is that, in the first program, the values of resistances R[01, RI II, RIN-1] and the equivalent resistance Req are all outputted to the console from within the series' prototype function while, in the second program, the same input and output values are outputted to the console from within the input function. REOIREMENT: The prototype functions input and series are to be both placed before the 'main' function, with the prototype function series' placed between the input and main functions.

Explanation / Answer

First Program

#include <stdio.h>
#include <conio.h>
#include<malloc.h>

void input();
void series(int R[],int size);
int main()
{
   input();
   getch();
   return 0;
}
void series(int R[],int size)
{
   int equivalentResistance=0;
   for(int i=0;i<size;i++)
   {
       equivalentResistance+=R[i];
   }

   printf("Equivalent Resistance to resistors connected in series : %d",equivalentResistance);
  
}
//Below method will be used to get input
void input()
{
   printf("Enter number of Resistor ");
   int size;
   int resistance;
   scanf("%d",&size);
   int *R=(int*)malloc(size*sizeof(int));

   printf("Enter value for %d Resistors one by one ",size);
   for(int i=0;i<size;i++)
   {
       scanf("%d",R+i);
   }

   series(R,size);
}

Second Program


#include <stdio.h>
#include <conio.h>
#include<malloc.h>

void input();
int series(int R[],int size);
int main()
{
   input();
   getch();
   return 0;
}
int series(int R[],int size)
{
   int equivalentResistance=0;
   for(int i=0;i<size;i++)
   {
       equivalentResistance+=R[i];
   }

   return equivalentResistance;
  
}
//Below method will be used to get input
void input()
{
   printf("Enter number of Resistor ");
   int size;
   int resistance;
   scanf("%d",&size);
   int *R=(int*)malloc(size*sizeof(int));

   printf("Enter value for %d Resistors one by one ",size);
   for(int i=0;i<size;i++)
   {
       scanf("%d",R+i);
   }

   resistance=series(R,size);
   printf("Equivalent Resistance to resistors connected in series: %d",resistance);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote