Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- void swap(double *x1 , double *x2)
- {
- double temp = *x1;
- *x1 = *x2;
- *x2 = temp;
- }
- double D(double a, double b,double c)
- {
- return pow(b,2)-4*a*c;
- }
- double f1(double a,double b,double c)
- {
- return pow(a,2) - 9*b*c;
- }
- double f2(double x)
- {
- return 4*x;
- }
- double f3(double x1, double x2)
- {
- return x2*sin(x1);
- }
- int main()
- {
- double a, b, c, d;
- printf("Enter coefficients a, b and c: ");
- scanf("%lf %lf %lf",&a, &b, &c);
- d = D(a,b,c);
- if (d > 0)
- {
- double x1, x2;
- x1 = (-b+sqrt(d))/(2*a);
- x2 = (-b-sqrt(d))/(2*a);
- if(x1>=x2)
- {
- swap(&x1,&x2);
- }
- printf("root1 = %.2lf and root2 = %lf;\n function = %lf",x1 , x2,f3(x1,x2));
- }
- else if (d == 0)
- {
- double x = -b/(2*a);
- printf("root1 = root2 = %lf;\nfunction = %lf",x,f2(x));
- }
- // if roots are not real
- else
- {
- printf("there are no real roots;\nfunction = %lf",f1(a,b,c));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement