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 kind of structure is a house?

562


What is the value of uninitialized variable in c?

578


What is the purpose of type declarations?

683


What does %p mean?

601


What are different storage class specifiers in c?

623






You are to write your own versions of strcpy() and strlen (). Call them mystrcpy() and mystrlen(). Write them first as code within main(), not as functions, then, convert them to functions. You will pass two arrays to the function in the case of mystrcpy(), the source and target array.

1785


How can you increase the size of a dynamically allocated array?

647


What is indirection in c?

631


while loop contains parts a) initialisation, evalution of an expression,increment /decrement b) initialisation, increment/decrement c) condition evalution d) none of the above

748


What is the acronym for ansi?

636


Explain what are bus errors, memory faults, and core dumps?

794


What is difference between union All statement and Union?

630


What is volatile variable how do you declare it?

570


What is int main () in c?

630


Explain what are multidimensional arrays?

607