C Language Write a program with a loop that solves quadratic

C Language.

Write a program with a loop that solves quadratic equations with coefficients read from the terminal.

A quadratic equation has the form: ax^2+bx+c=0 The two solutions are given by the formula: x_1, 2 = -b plusminus squareroot b^2-4ac/2a Write a program with a loop that solves quadratic equations with coefficients read from the terminal. Write all code for this problem in a file p1.c. Write a function called computeSolutions () that computes the real (in the set R) solutions to the quadratic equations. The function prototype must be: int computeSolutions(double a, double b, double c, double* px1, double* px2); The function uses formula (1) above to compute solutions X_i and x_2. The function returns the number of distinct real solutions, as follows: if b^2- 4ac0 then the solutions are distinct and the function returns 2, after writing in *px1 the value of X_1 and in *px2 the value of x_2. To keep the problem focused we can assume that the user never enters a value for coefficient a that is equal to 0. Write a function readCoefficients() that reads from the terminal the coefficients a. b, c of a quadratic equations. The function prototype must be:

Solution

#include <stdio.h>
#include <math.h>
int computesolution(double a, double b, double c, double*px1, double*px2)
int readcoeeficients(double *pa, double *pb, double *pc)
int main()
{
double *px1, *px2;
   int readcoeeficients()
   computesolution(double pa, double pb, double pc, double *px1, double *px2)
  
   getch();
}

int readcoeeficients()
{
double pa, pb, pc;
printf(\"Enter coefficients pa, pb and pc: \");
scanf(\"%lf %lf %lf\",&pa, &pb, &pc);
   }
   return();
}

int computesolution(double a, double b, double c, double*px1, double*px2)
{
double determinant;
determinant = b*b-4*a*c;

if (determinant > 0)
{
x1 = (-b+sqrt(determinant))/(2*a);
x2 = (-b-sqrt(determinant))/(2*a);
   printf(\"the solutions are distinct);
   *px1=x1;
   *px2=x2;
   return 2;
}

//condition for real and equal roots
else if (determinant == 0)
{
x1 = x2 = -b/(2*a);
   *px1=x1;
   *px2=x2;
return 1;
}

else
{
//solutions are complex number
   *px1=0;
   *px2=0;      
}
}

C Language. Write a program with a loop that solves quadratic equations with coefficients read from the terminal. A quadratic equation has the form: ax^2+bx+c=0
C Language. Write a program with a loop that solves quadratic equations with coefficients read from the terminal. A quadratic equation has the form: ax^2+bx+c=0

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site