write a c program to find the roots of a quadratic equation
ax2 + bx + c = 0

Answer Posted / shariful islam

#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


Please Help Members By Posting Answers For Below Questions

What is wrong in this statement?

606


What is pragma in c?

629


Tell us two differences between new () and malloc ()?

614


What is the difference between exit() and _exit() function in c?

584


What are the primitive data types in c?

579






Why is c not oop?

539


I need a sort of an approximate strcmp routine?

659


Define C in your own Language.

640


How can I insert or delete a line (or record) in the middle of a file?

575


What is extern keyword in c?

644


Where does the name "C" come from, anyway?

645


In c language can we compile a program without main() function?

580


How do I use void main?

632


Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)

815


write a program to rearrange the array such way that all even elements should come first and next come odd

1762