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.
#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 |
difference between a for loop and a while loop? what are its uses in c language?
how 2 write a program of this pattern usin for loop?? 1 2 3 4 5 6 7 8 9 10
in single linked list , each node contains data and address of next node. if middle of list the node is damaged/crashed then how to find where the link is failed and how to get the all the data which is stored after the crashed node?
i have applied for junior engg. signal II please send me questions papers for it
what is the heat insulation material is adaptable for a flue gas duct that carries waste heat from brick kiln to brick drier and what temperature is required to maintain at the tunnel to dry adobe bricks adequately
WHAT IS CEASER II PIPING Stands For?
how u test the idoc in inbound and outbound?
Sorting is not possible by using which of the following methods? (Insertion, Selection, Exchange, Deletion)
is it possible to apply for visa interview in 4-1 sem for doing ms in usa
what is the best part of your life ?
what are the simlerities between macro and subroutine
how many tranformations are there in informatica?
Civil Engineering (5086)
Mechanical Engineering (4456)
Electrical Engineering (16639)
Electronics Communications (3918)
Chemical Engineering (1095)
Aeronautical Engineering (239)
Bio Engineering (96)
Metallurgy (361)
Industrial Engineering (259)
Instrumentation (3014)
Automobile Engineering (332)
Mechatronics Engineering (97)
Marine Engineering (124)
Power Plant Engineering (172)
Textile Engineering (575)
Production Engineering (25)
Satellite Systems Engineering (106)
Engineering AllOther (1379)