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

USING VISUAL STUDIO Task on VISUAL STUDIO 2015-Using loop structures We want a p

ID: 3861458 • Letter: U

Question

USING VISUAL STUDIO

Task on VISUAL STUDIO 2015-Using loop structures

We want a program that calculates the total resistance of a resistance network which consists of a chain connected in serie of parallel resistors, as illustrated. The number of resistors in each parallel connection and the number of parallel connections are not known at program startup.

The program will work as follows:

>One resistance value is read at a time.

>When the uploaded resistance value = 0, means that there is the end of a parallel connection - we have come to a node.

> If the scanned value is <0, means that there is an end to the network and total resistance will be shown. (Note: The program will thus ends when the user enters R <0, but remember that user perhaps first gives R = 0, then R <0.)

TIPS:

>Calculations are performed as user enters values. You do not need to store all resistance values.

>It is easiest to work with conductances in parallel connections and resistances in

connections in serie.

>It is an advantage if the program shows intermediate results along the way. Then it is easier to

check if it calculates right.

Explanation / Answer

Program logic:

main()

{

int m=1,r=0,tot=0,p=0;

While(1)

{

//Get register value r;

printf("enter value of r");

scanf("%d",&r);

If (r>0)

{

p=p+(1/r);

}

If((m==0)&&(r<0))

Break;

If(r==0)

{

If(p>0)

tot=tot+(1/p);

p=0;

m=0;

Continue;

}

}

Printf("total resistance of ckt=%d",tot);

return;

}