Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int uravnenie(float a, float b, float c, float *px1, float *px2);
  6.  
  7.  
  8. void main() {
  9. int casse;
  10. float a, b, c, x1, x2;
  11. printf("Enter a: "); scanf("%f", &a);
  12. printf("Enter b: "); scanf("%f", &b);
  13. printf("Enter c: "); scanf("%f", &c);
  14.  
  15. casse = uravnenie(a, b, c, &x1, &x2);
  16.  
  17. switch(casse){
  18. case 1:
  19. printf("\nNo solution"); break;
  20. case 2:
  21. printf("\nEvery x"); break;
  22. case 3:
  23. printf("\nx = %f", x1); break;
  24. case 4:
  25. printf("\nNo actual solutions"); break;
  26. case 5:
  27. printf("\nx1 = %f\nx2 = %f", x1, x2); break;
  28. }
  29. }
  30.  
  31. int uravnenie(float a, float b, float c, float *px1, float *px2){
  32. float D;
  33. if (a == 0){
  34. if (b == 0){
  35. if (c == 0) return 2;
  36. else return 1;
  37. }
  38. else {
  39. *px1 = -c / b;
  40. return 3;
  41. }
  42. }
  43. else {
  44. D = b*b - 4*a*c;
  45. if (D < 0) return 4;
  46. else {
  47. *px1 = (-b - sqrt(D)) / (2 * a);
  48. *px2 = (-b + sqrt(D)) / (2 * a);
  49. return 5;
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement