This project will familiarize the student with if, if -else, and while statement
ID: 3781723 • Letter: T
Question
This project will familiarize the student with if, if -else, and while statements. Write a program that calculates the equivalent resistance of a network of series or parallel resistors. The program should prompt for the following input: parallel or series calculation? Loop for the number of elements (either enter the number of resistors, or terminate the value-entering loop with a sentinel value.. if you insist.) The value of each resistor After calculating the equivalent resistance, the program should output this value. Make use of one or more of the following control statements: 'if/else' statement 'while' loop Parallel: R_equivalent = 1/1/R_1 + 1/R_2 + ... + 1/R_N, and R_equivalent = R_1 + R_2 + .. + R_N, where N is the number of resisters.Explanation / Answer
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char choice;
int n;
float arr[100];
printf("Parallel Or series ?????? "); \ Asks User for series or parallel calculations
printf("for paralle press P or For series press S "); \ asks for choice
scanf("%c",&choice); \ user enters choice
printf("Enter number of resistors "); \ asks fr number of resistors
scanf("%d",&n);
printf("enter the values of %d resistors",n); \asks for each value of resistors
for(int i=1;i<=n;i++)
{
printf("enter the value of resister R%d = ",i);
scanf("%f",arr[i]);
}
if(choice=='p') // compare if choice id for parallel if yes it enters the if block else move to else if block
{
float temp=0.0,req;
for(int i=1;i<=n;i++)
{
temp+=(1/arr[i]); \ calculates temp = 1/r1 + 1/r2 ....... + 1/rn;
}
req=(1/temp); \ calculates req= 1/(1/r1 + 1/r2 ....... + 1/rn;)
printf("R equivalent is %f Ohm",req); \ prints the result
}
else if(choice=='s') // if choice is for series it enters this block
{
int temp=0;
for(int i=1;i<=n;i++)
temp+=arr[i]; // calculates req= r1+r2+ ....... rn
printf("R equivalent is %d ohm",temp);// prints the result
}
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.