Advertisement
Guest User

נוסחת השורשים

a guest
Dec 7th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. double f(double a,double b,double c,double *p1,double *p2)
  4. {
  5.     double m;
  6.     if(a==0 || (b*b-4*a*c)<0)
  7.         return 0;
  8.     if((b*b-4*a*c)==0)
  9.     {
  10.         *p1=(-b)/2.0*a;
  11.         return 1;
  12.     }
  13.     m=sqrt(b*b-4*a*c);
  14.     *p1=((-b)+m)/(2.0*a);
  15.     *p2=((-b)-m)/(2.0*a);
  16.     return 2;
  17. }
  18. void main()
  19. {
  20.     double a,b,c,k;
  21.     double x1,x2;
  22.     printf("Enter a , b , c:  ");
  23.     scanf("%lf%lf%lf",&a,&b,&c);
  24.     k=f(a,b,c,&x1,&x2);
  25.     if(k==0)  printf("No Solution\n");
  26.     if(k==1)  printf("x1: %.2lf\n",x1);
  27.     if(k==2)  printf("x1: %.2lf    x2: %.2lf\n",x1,x2);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement