SHOW:
|
|
- or go back to the newest paste.
| 1 | /* C programme to solve quadractic equation , (for real roots only/ when b²-4ac >= 0 , for ax²+bx+c=0 */ | |
| 2 | #include<stdio.h> | |
| 3 | #include<math.h> | |
| 4 | int main(void) | |
| 5 | {
| |
| 6 | /* [ ax²+bx+c=0 ] */ | |
| 7 | float a,b,c,x1,x2; | |
| 8 | printf("Please enter the value of a:\n");
| |
| 9 | scanf("%f",&a);
| |
| 10 | printf("Please enter the value of b:\n");
| |
| 11 | scanf("%f",&b);
| |
| 12 | printf("Please enter the value of c:\n");
| |
| 13 | scanf("%f",&c);
| |
| 14 | x1=((-b)+sqrt((b*b)-(4*a*c)))/(2*a); | |
| 15 | x2=((-b)-sqrt((b*b)-(4*a*c)))/(2*a); | |
| 16 | printf("First root is: %f\n",x1);
| |
| 17 | printf("Second root is: %f\n",x2);
| |
| 18 | return 0; | |
| 19 | } |