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

cs homework Program chapter 3_practise #3_p.95 this program print the values of

ID: 3792926 • Letter: C

Question

cs homework

Program chapter 3_practise #3_p.95 this program print the values of volt_1 and volt_2 if the difference between volt_1 and volt_2 is larger #include #include int main(void) {/* Declare and initialize variables. */double volt_1, volt_2;/* Input variables from the keyboard */printf("Input first voltage: "); scanf("%lf ", &volt;_l); printf("Input second voltage: "); scanf("%lf ", &volt;_2);/* Conditional Statement and print the output or decision */If (fabs(volt_l-volt_2)>10.0) printf ("The difference between two voltage is larger than 10.0 n "); else printf ("The difference between two voltage is smaller than 10.0 ");/* Exit program. */return 0;} HOMEWORK #4 find the solution of a quadratic equation input a, b and c output: print the solution of xl and x2 if real print "the roots are complex number" if it is not real (extra credit for complex number solution)

Explanation / Answer

#include <stdio.h>
#include <math.h>

int main(int argc, char *argv[]) {
  
   float a,b,c; //to store a,b,c
  
   float disc; //to store discriminant of quadratic equation
  
   float root1,root2; //to store roots
   printf("Enter the values of a,b,c separated by spaces");
  
   scanf("%f %f %f",&a,&b,&c); //input a,b,c
  
   disc=b*b-4*a*c; //calculate discriminant
  
   if(disc<0){ //if discriminant<0 roots are complex otherwise real
       printf("the roots are complex number ");
       float k=-b/(2*a);
       float l=sqrt(-disc)/(2*a);
       printf("x1 %f+i%f x2 %f_i%f",k,l,k,l);
   }else{
       printf("the roots are real number ");
       root1=(-b+sqrt(disc))/(2*a); //use the formula -b+_sqrt(disc)/2a to calculate roots
       root2=(-b-sqrt(disc))/(2*a);
       printf("x1 %f x2 %f",root1,root2);
   }


  
return 0;


}