Friday, 19 February 2021
find a value of a quadric equation
#include
main()
{
float a,b,c,d,root1,root2;
printf("Enter value of a,b and c:");
scanf("%f%f%f",&a,&b,&c);
d=b*b-4*a*c;
if(d<0)
{
printf("Roots are complex number.\n");
printf("Roots of quadric equation are: ");
printf("%3f+%3fi and ",(-b/(2*a)),sqrt(-d)/(2*a));
printf("%3f-%3fi",(-b/(2*a)),sqrt(-d)/(2*a));
}
else if(d==0)
{
printf("Roots are equal.\n");
root1=root2=(-b/(2*a));
printf("Roots of quadric equation are: ");
printf("%3f and %3f",root1,root2);
}
else
{
printf("Roots are real number\n");
root1=(-b+sqrt(d))/(2*a);
root2=(-b-sqrt(d))/(2*a);
printf("Roots of quadric equation are: ");
printf("%3f and %3f",root1,root2);
}
return 0;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment