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

Code1: #include int main(){ int res1, res2, res; printf(\"\ Enter Value of Each

ID: 3784621 • Letter: C

Question

Code1:

#include
int main(){
    int res1, res2, res;
  
   printf(" Enter Value of Each Resistance 1: ");
   scanf("%d", &res1);
   printf(" Enter Value of Each Resistance 2: ");
   scanf("%d", &res2);
   res = res1+res2;
   printf(" Equivalent Series Resistance : %d Kohm ", res);

   return (0);
}

----------------------------------------------------------------------------------------------------------

Code2:

#include
int main(){
    int res1, res2, res;
  
   printf(" Enter Value of Each Resistance 1: ");
   scanf("%d", &res1);
   printf(" Enter Value of Each Resistance 2: ");
   scanf("%d", &res2);
   res = (res1*res2)/(res1+res2);
   printf(" Equivalent Parellel Resistance : %d Kohm ", res);

   return (0);
}

Take the two programs and combine them into a single program(using c not c++) that uses an if and else statement to calculate R total either in series or parallel based on the users preference (ask the users which way they want the resistance calculated).

Explanation / Answer

main.c

#include<stdio.h>
int main(){
    int res1, res2, res,start;

   printf("Enter Value of Each Resistance 1: ");
   scanf("%d", &res1);
   printf(" Enter Value of Each Resistance 2: ");
   scanf("%d", &res2);

   printf(" Enter 0 to quite Enter 1 for series circuit Enter 2 for parallel circuit: ");
   scanf("%d",&start);

if (start==0){
    return 0;
}
else if (start==1){
    res = res1+res2;
   printf(" Equivalent Series Resistance : %d Kohm ", res);
}
else if (start==2){
res = (res1*res2)/(res1+res2);
   printf(" Equivalent Parellel Resistance : %d Kohm ", res);
}
else {
    printf("Error!");}
   return (0);
}

Output:-