In this problem usefunction. Provide a function prototype for each function befo
ID: 3618840 • Letter: I
Question
In this problem usefunction. Provide a function prototype for each function before themain function. The function prototype should have descriptive namesfor the function and for each parameter. Put very little code inthe main function. Each function should be preceded with a shortcomment giving:
- A long line ofasterisks as an eye catcher
- The purpose of thefunction
- Parameters, otherinput, and initial conditions
- Return values,other results, and final conditions provided
The equationax2 + bx + c = 0 may have two real numbers as solutions,for some values of a, b, and c. Write a program to inputinteger values for a, b and c, and produce output for the two realvalues of x that are solutions. Allow the user to enter the valuesof a, b, and c. Your program need to only work for the case wheretwo real solutions are produced. Compute the solutions as floatingpoint results with 2 decimal precision.
Explanation / Answer
please rate - thanks as per your request it worked fine for me, but the question said Your program needto only work for the case where two real solutions areproduced so I got rid of those checks #include<stdio.h>#include<math.h>
#include<conio.h>
void input(double*,double*,double*);
void solve(double,double,double);
int main()
{double a,b,c;
input(&a,&b,&c);
solve(a,b,c);
getch();
return 0;
}
void solve(double a,double b,double c)
{double discriminant,denom;
discriminant=pow(b,2.)-4*a*c;
denom=2.*a;
printf("The roots of %.2f x^2+%.2fx+%.2f are: ",a,b,c);
printf("%.2f and%.2f ",(-b+sqrt(discriminant))/denom,(-b-sqrt(discriminant))/denom);
}
void input(double* a,double* b,double* c)
{
printf("For the equation ax^2+bx+c: ");
printf("Enter a: ");
scanf("%lf",a);
printf("Enter b: ");
scanf("%lf",b);
printf("Enter c: ");
scanf("%lf",c);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.