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: 3761768 • 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-1] 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 RIO), RI 1201-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[0], R[1] ..., R[N-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

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

Program 1

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

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

void series (int *,int);
void input_arr(int N)
{
   int i=0,j=0;
   int *Rser;
   Rser=(int *) malloc(N);
   for (i=0;i<N;i++)
   {
       printf(" Enter The Value of Resister-%d:",i+1);
       scanf("%d",&j);
       *(Rser+i)=j;

   }
   series(Rser,N);
}
void series(int *rarr, int n)
{
   int i=0,Req=0,N=n,*Rser;
   Rser=rarr;
   for(i=0;i<N;i++)
   {
       Req=Req+(*(Rser+i));
   }
   printf(" ========================");
   printf(" The Values of Resistors entered are: ");
   for(i=0;i<N;i++)
   {
   printf(" R%d=%d",i+1,*(Rser+i));
   }
   printf(" =========== The Equivalent Series Resistance is %d Ohm.", Req);
   free(Rser);

}
void main()
{
   int N=0;
   printf(" Enter The Number of Resistors:");
   scanf("%d",&N);
   input_arr(N);
   getch();

}

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

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

Program 2

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

#include<conio.h>
#include<stdio.h>
#include<alloc.h>
int series (int *,int);
void input_arr(int N)
{
   int i=0,j=0,Req=0;
   int *Rser;
   Rser=(int *) malloc(N);
   for (i=0;i<N;i++)
   {
       printf(" Enter The Value of Resister-%d:",i+1);
       scanf("%d",&j);
       *(Rser+i)=j;
   }
   Req=series(Rser,N);

   printf(" ========================");
   printf(" The Values of Resistors entered are: ");
   for(i=0;i<N;i++)
   {
   printf(" R%d=%d",i+1,*(Rser+i));
   }
   printf(" =========== The Equivalent Series Resistance is %d Ohm.", Req);
   free(Rser);

}
int series(int *rarr, int n)
{
   int i=0,Req=0;
   int len=n;
   int *Rser;
   Rser=rarr;
   for(i=0;i<len;i++)
   {
       Req=Req+(*(Rser+i));
   }
   return(Req);
}
void main()
{
   int N=0;
   printf(" Enter The Number of Resistors:");
   scanf("%d",&N);
   input_arr(N);
   getch();

}

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

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