Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- double f(double a,double b,double c,double *p1,double *p2)
- {
- double m;
- if(a==0 || (b*b-4*a*c)<0)
- return 0;
- if((b*b-4*a*c)==0)
- {
- *p1=(-b)/2.0*a;
- return 1;
- }
- m=sqrt(b*b-4*a*c);
- *p1=((-b)+m)/(2.0*a);
- *p2=((-b)-m)/(2.0*a);
- return 2;
- }
- void main()
- {
- double a,b,c,k;
- double x1,x2;
- printf("Enter a , b , c: ");
- scanf("%lf%lf%lf",&a,&b,&c);
- k=f(a,b,c,&x1,&x2);
- if(k==0) printf("No Solution\n");
- if(k==1) printf("x1: %.2lf\n",x1);
- if(k==2) printf("x1: %.2lf x2: %.2lf\n",x1,x2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement