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

1. Create a script with if, else if, and else conditionals to calculate the Tota

ID: 3667237 • Letter: 1

Question

1. Create a script with if, else if, and else conditionals to calculate the Total Resistance (R_T) 1) r1 , r2, and r3 are connected in series manner. (R_T= r1+r2+r3)
2) r1, r2, and r3 are connected in parallel manner.(R_T = 1/((1/r1)+(1/r2)+(1/r3)) ) 3) r1 is connected to the parallelly connected r2 and r3 in series manner.

(R_T = r1 + r2xr3/(r2+r3) ) The output should be

The Total Resistance is [your result] ohms since r1, r2, r3 are connected in [series, parallel, combination] manner. r1 = 10 , r2 = 20 , and r3 = 30 .

2. Repeat problem 1. This time use “switch”.

3. Create a script that will add all integers between 1 (initial) and 100 (final). Also, create another script that will do the same operation,bBut this time use decrement operator so can have 100 for the initial integer and 1 for the final integer.

4. Let’s create our own quadratic equation solver.

a) First, try using loop with changing numbers x from 0 to 10. (This is just the completion of the work that we tried in class.) (I.E: Create script with loops that will find values of x’s that will satisfy the equality ax^2+bx+c=0) Try with a = 1, b=-4, and c =3 and a =1, b=-4 and c = 4. (Let’s stick to integer roots)

b) Second, we can try [–b (+/-) sqrt(b^2-4ac)] / (2a), but this requires a lot of conditions (please pardon the pun.), since we can have three different forms of outcome.

float a, b, c;
float REAL1, IMAG1, IMAG2; a=1.0; b=4.0; c= 3.0;

// a=1.0; b=4.0; c= 5.0 ;// a=1.0; b=4.0; c= 4.0 (Try with these 3 sets of a, b, c) REAL1=-b/2;

IMAG1=b*b-4*a*c; IMAG2=4*a*c-b*b;

(USING DEV C++)

Explanation / Answer

1. Create a script with if, else if, and else conditionals to calculate the Total Resistance (R_T) 1) r1 , r2, and r3 are connected in series manner. (R_T= r1+r2+r3)

2) r1, r2, and r3 are connected in parallel manner.(R_T = 1/((1/r1)+(1/r2)+(1/r3)) ) 3) r1 is connected to the parallelly connected r2 and r3 in series manner.

The Total Resistance is [your result] ohms since r1, r2, r3 are connected in [series, parallel, combination] manner. r1 = 10 , r2 = 20 , and r3 = 30 .

Script for Question 1:

double R_T = 0.0, r1 = 10, r2 = 20 , r3 = 30;
if (series == serial)
{
   R_T = r1+r2+r3;  
}
else if(series == parallel)
{
   R_T = R_T = 1/((1/r1)+(1/r2)+(1/r3)) ;
}
else
{
   R_T = r1 + r2xr3/(r2+r3) ;
}

Script for Question 2:

double R_T = 0.0, r1 = 10, r2 = 20 , r3 = 30;
switch(ch)
{
   case 's':
       R_T = r1+r2+r3;  
       break;
   case 'p':
        R_T = R_T = 1/((1/r1)+(1/r2)+(1/r3)) ;
       break;
   case 'c':
       R_T = r1 + r2xr3/(r2+r3) ;
   default:
       return 0;
}

Script for Question 3:

int i =0, sum =0;
for(i = 1; i<=100; i++)
   sum = sum + i;
  
Reverser order :

for(i=100; i>=0; i--)
   sum = sum + i;
  

Script for Question 4:

#include <stdio.h>
#include <math.h> /* This is needed to use sqrt() function.*/
int main()
{
float a, b, c, determinant, r1,r2, real, imag;
printf("Enter coefficients a, b and c: ");
scanf("%f%f%f",&a,&b,&c);
determinant=b*b-4*a*c;
if (determinant>0)
{
      r1= (-b+sqrt(determinant))/(2*a);
      r2= (-b-sqrt(determinant))/(2*a);
      printf("Roots are: %.2f and %.2f",r1 , r2);
}
else if (determinant==0)
{
    r1 = r2 = -b/(2*a);
    printf("Roots are: %.2f and %.2f", r1, r2);
}
else
{
    real= -b/(2*a);
    imag = sqrt(-determinant)/(2*a);
    printf("Roots are: %.2f+%.2fi and %.2f-%.2fi", real, imag, real, imag);
}
return 0;
}