Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

!@#$% Your C program will do the following tasks: i. Prompt and obtain the coefficients a, b, and c ii. In order to determine whether

!@#$%

Your C program will do the following tasks: i. Prompt and obtain the coefficients a, b, and c

ii. In order to determine whether the roots are complex, it will calculate the quantity b2 4ac

iii. If this quantity is negative, then the program will print out the message "The roots are complex"

iv. If not, the program will calculate the two real roots of the quadratic equation as (b + (sqrt(b2 4ac))/2a and (b (sqrt(b2 4ac))/2a.

sample output:

Enter value for a:

Enter value for b:

Enter value for c:

Roots are: (((depends on values entered)))

Issue:

I have tried to do this project and regardless of what numbers I enter for a,b, and c, I get 0s for the roots in any of the situations in the project statement. also, the type is supposed to be double for the values but whenever i try that i get errors so i have left them as int for now. if someone could change them to type double and correct the issue that is giving me 0s everytime, that would be much appreciated.

Thanks!

My code:

#include #include void getData (int*, int*, int*); int checkSolution (int, int, int); int main() { int a,b,c; getData (&a, &b, &c); checkSolution (a, b, c); return 0; } void getData (int* a, int* b, int* c) { printf(" \tQuadratic Equation: a*x^2+b*x+c = 0"); printf(" \tEnter value for a: "); scanf("%d", a); printf(" \tEnter value for b: "); scanf("%d", b); printf(" \tEnter value for c: "); scanf("%d", c); } int checkSolution (int a, int b, int c) { int d; float root1, root2; if(a == 0 && b == 0) { printf(" \t\tNo Solution!"); return -1; } else { printf("the roots of a and b are: %0.2f\t %0.2f", root1, root2); return 1; } if (a == 0) { float root = -(c/b); printf(" \t\tOnly one solution: %0.2f", root); return -2; } else { printf("the roots of a and b are: %0.2f\t %0.2f", root1, root2); return 2; } d = b*b-4*a*c; if(d<0) { printf("No real roots exist!"); return -3; } else { printf("the roots of a and b are: %0.2f\t %0.2f", root1, root2); return 3; } root1 = (-b + sqrt(d))/(2*a); root2 = (-b - sqrt(d))/(2*a); printf(" \t\tThe two roots are: %0.2f, %0.2f", root1, root2); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions