Write a program to compute the real roots of a quadratic equation (ax^2 + bx +c = 0). The roots can be calculated using the quadratic formula.
Your program is to prompt the user to enter the constants (a, b, c). It is then to display the roots based on the following rules:
a. If both a and b are zero, there is no solution.
b. If a is zero, there is only one root (-c/b).
c. If the discriminate (b^2 - 4ac) in negative, there are no real roots.
d. For all other combinations, there are two roots.
Update:Yes, everything you said is true. I need to write a program that uses that information and calculates it for me.
Copyright © 2024 Q2A.ES - All rights reserved.
Answers & Comments
Verified answer
include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,s1,s2,y1,y2,r,s;
int a,b,c;
clrscr();
printf("Enter the values of a,b,c");
scanf("%d %d %d",&a,&b,&c);
r=(b*b)-(4*a*c);
if(a==0 && b==0)
printf("\n No solution \n");
else if(a==0)
{
printf("Only one root %d",-(c/b));
}
else if(r<0)
printf("There is no real roots");
else
{
s=sqrt(r);
s1=-b + s;
s2=-b - s;
y1=s1/2*a;
y2=s2/2*a;
printf("The roots are %d %d",y1,y2);
}
getch();
}
this works fine but when a is zero condition occurs,the only root -c/b will not get the value with exact decimals as i declared that with int,so if u need that to more accurate then u can use float.if u have any doubts mail me at [email protected]
So...based on this very detailed programming assignment, you probably have to write 3 if statements, right? a. b. and c. all start with the word if.
And you probably need an else statement. d. is an else, although it doesn't come out and say it the way the if statements do.
So...Show us your if statements, and, if they aren't working, we can probably tell you why they aren't.
But it's doubtful that anyone here will just write them for you. We wouldn't be helping you if we did.
We would not be helping you at all if we just did your homework for you. If you do not understand the theory behind how to do something like this, perhaps these two links will help you:
http://en.wikipedia.org/wiki/C_%28programming_lang...
http://www.mathnstuff.com/math/spoken/here/2class/...
bumb..