GrammaryN Ntro Pro 8Tell me whet you want to do 1 Normal 1 No S pa. Heading 1 He
ID: 2291360 • Letter: G
Question
GrammaryN Ntro Pro 8Tell me whet you want to do 1 Normal 1 No S pa. Heading 1 Heading 2 Title Subtitle Subtle Em.... mphasis Intense E. Strong Program 8 A quadratic equation is in the form "ax2+ bx+ c-O", where a, b, and c represent floating-point values. Write a program that asks the user for the three values and output the result. The program should contain two functions as follows: Function "Root" which takes three float type parameters and return a float corresponding to b2-4"a"c. Function "Sol" which take three float parameters and two float pointer parameters, this function has no return. - - The program should output a statement indicating the number of possible solutions and depending the number of solutions, output the proper number of statements for them. Note: do not repeat any calculations, meaning that function Sol need to call function root instead of repeating the calculations done in Root. Check drop box for submission deadline. Lian+s Srok Grade Leom MussExplanation / Answer
#include <stdio.h>
#include <math.h>
/* function declaration */
float Root(float a, float b, float c);
float Sol(float a, float b, float c);
int main () {
float a,b,c;
printf("Enter coefficients a, b and c: ");
scanf("%f %f %f",&a, &b, &c);
Sol(a,b,c);
}
/* function returning the value */
float Root(float a, float b, float c) {
/* local variable declaration */
float d;
d=b*b-4*a*c;
return b;
}
float Sol(float a, float b, float c) {
float determinant, root1,root2, realPart, imaginaryPart;
determinant = Root(a,b,c);
// condition for real and different roots
if (determinant > 0)
{
// sqrt() function returns square root
root1 = (-b+sqrt(determinant))/(2*a);
root2 = (-b-sqrt(determinant))/(2*a);
printf("root1 = %.2lf and root2 = %.2lf",root1 , root2);
}
//condition for real and equal roots
else if (determinant == 0)
{
root1 = root2 = -b/(2*a);
printf("root1 = root2 = %.2lf;", root1);
}
// if roots are not real
else
{
realPart = -b/(2*a);
imaginaryPart = sqrt(-determinant)/(2*a);
printf("root1 = %.2lf+%.2lfi and root2 = %.2f-%.2fi", realPart, imaginaryPart, realPart, imaginaryPart);
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.