fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int rizes(float a, float b, float c, float *x1, float *x2);
  5.  
  6. main()
  7. {
  8. float a,b,c,riza1,riza2;
  9. int plithos;
  10.  
  11. /* 1. Diavasma tis eisodou */
  12.  
  13. printf("Dwse to a: ");
  14. scanf("%f",&a);
  15.  
  16. printf("Dwse to b: ");
  17. scanf("%f",&b);
  18.  
  19. printf("Dwse to c: ");
  20. scanf("%f",&c);
  21.  
  22. /* 2. Ypologismos rizwn */
  23. plithos=rizes(a,b,c,&riza1, &riza2);
  24.  
  25. /* 3. Ektypwsi tou apotelesmatos */
  26.  
  27. if (plithos==0)
  28. printf("Den exei pragmatikes rizes");
  29. else if (plithos==1)
  30. printf("Exei dipli riza tin %f", riza1);
  31. else
  32. printf("Exei rizes: %f kai %f", riza1, riza2);
  33.  
  34. }
  35.  
  36. int rizes(float a, float b, float c, float *x1, float *x2)
  37. {
  38. float D;
  39.  
  40. D=b*b-4*a*c;
  41.  
  42. if (D<0)
  43. return 0;
  44. else if (D==0)
  45. {
  46. *x1 = -b/(2*a);
  47. return 1;
  48. }
  49. else
  50. {
  51. *x1=(-b+sqrt(D))/(2*a);
  52. *x2=(-b-sqrt(D))/(2*a);
  53. return 2;
  54. }
  55. }
  56.  
Success #stdin #stdout 0.01s 5284KB
stdin
45
stdout
Dwse to a: Dwse to b: Dwse to c: Exei rizes: inf kai -inf