ax^2 + bx + c = 0
- LOGIC:
Since we know that sum of the roots is : x1 + x2 = -b/a and product of roots is : x1*x2 = c/a. So we'll first take the input of coefficients from user and calculate sum and product and print it.
- ALGORITHM:
- Start
- Input values of a, b and c from user
- Calculate sum of roots : -b/a
- Calculate product of roots : c/a
- Print sum of roots : x1+x2 = sum
- Print product of roots : x1*x2 = prod
- End
- CODE:
#include <stdio.h>
int main ()
{
//declare variables
float a,b,c,sum,prod;
printf("Enter the values of a, b and c : ");
//input the values of a, b and c from user
scanf("%f %f %f", &a, &b, &c);
//calculate sum of roots
sum = -b/a;
//calculate product of roots
prod = c/a;
//print sum and product of roots
printf("Sum of the roots is : %.2f",sum);
printf("\n Product of the roots is : %.2f",prod);
return 0;
}
- OUTPUT:
Enter the values of a, b and c : 1 4 4
Sum of the roots is : -4.00
Product of the roots is : 4.00
That's all for today. If you get any problem then don't hesitate to ask.
If the post was helpful, then
Share, Subscribe and keep Coding...
Comments
Post a Comment