Write a C program to solve the quadratic equation ax^2+bx+c=0.
A quadratic equation has two roots which are given by the following two formulas:
root1= -b+sqrt(b^2-4*a*c)/2*a
root1= -b-sqrt(b^2-4*a*c)/2*a
The program request the user for input a,b,c and the output will be root1 and root2.
Answer Posted / sharifulislam
#include<stdio.h>
#include<math.h>
int main(){
float a,b,c;
float d,root1,root2;
printf("Enter quadratic equation in the format ax^2+bx+c: ");
scanf("%fx^2%fx%f",&a,&b,&c);
d = b * b - 4 * a * c;
if(d < 0){
printf("Roots are complex number.
");
return 0;
}
root1 = ( -b + sqrt(d)) / (2* a);
root2 = ( -b - sqrt(d)) / (2* a);
printf("Roots of quadratic equation are: %.3f , %.3f",root1,root2);
return 0;
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Which is better field cad/cam in mechanical or film editing/animation is better salary wise?
What are the main assumptions that we make when we model potential flow?
what is the difference between verification and validation
A rectangular sheet dimensions a x b is to be made into an open-topped box by cutting a square of side h from each corner and folding the 4 sides up. Find the value of h which allows the maximum volume of the box?
Index of an Array containing 'n' aliment varies from________to_______
WHAT IS THE MEANING OF FLASHING VD AND FD INSTALLATION PLENIUM BOXES IN CENTRAL AIR CONDITION
What is the significance of superconductors?
Has anyone attended interviews in IITs for positions like Research fellowships/assistants? If yes, please share the experience about how complex the interview was, etc. etc.
how to send request to the direct server rather than proxy server
i want to knw about what is lead,survey, oppertuinty , questionary,sales order,quotation,marketng conecpts in deatil and how it works in SAP CRM. Please send to my email- id as soon as possible. Thanks in Advance . :) nimi.nimisha1@gmail.com
How do you reset or reseed the IDENTITY column?
how will u recieve idoc
when will the group1&group2 exams will be held
What is IPSec?
i want techical questions on c and java with code part