The program asks the user to input values for a, b, and c. It then implements a function called quad that takes in those values plus two additional variables to store the square roots. The quad function calculates the discriminant and returns the number of roots, storing any roots in the additional variables. It prints statements with the appropriate roots depending on if the discriminant is positive, zero, or negative.
Write a program that asks the user for a- b- and c- Implement a funct.docx
1. Write a program that asks the user for a, b, and c. Implement a function called quad int
quad(double a, double b, double c, double Br1, double Br2) Return the number of roots. r1
should have the first squareroot (if applicable) r2 should have the second squareroot (if
applicable)
Solution
#include <stdio.h>
#include< math.h>
#include <conio.h>
void quad(int a,int b,int c);
void main()
{
double a,b,c;
clrscr();
printf("enter the coefficients of x2,x and constant values ");
scanf("%f%f%f",&a,&b,&c);
quad(a,b,c);
getch();
}
void quad(int a,int b,int c)
{
double D,r1,r2,m,s;
D=(b*b-4*a*c);
2. if(D>0)
{
printf("roots are real and distinct");
r1=((-b+pow(D,0.5))/2*a);
r2=((-b-pow(D,0.5))/2*a);
printf("The roots are %f %f",r1,r2);
}
else if(D==0)
{
printf("roots are real and equal ");
r1=(-b/(2*a));
r2=r1;
printf("roots are %f,%f",r1,r2);
}
else
{
D=-D;
printf("roots are imaginary");
m=(-b/(2*a));
s=(pow(D,.5)/(2*a));
printf("roots are %f+i%f and %f-i%f",m,s,m,s);
}
}