Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define CRT_SECURE_NO_WARNINGS
  4. void main()
  5. {
  6. int num, a, b, c, choice;
  7. double d, Root, Root2, X1, X2;
  8.  
  9. /*printf("1. 3 digits number organizing.\n");
  10. printf("2. Linear equation calculator.\n");
  11. printf("3. Exit.\n");
  12. scanf_s("%d", &choice);
  13. switch (choice)
  14. {
  15. case 1: printf("Insert a 3 digits number.\n");
  16. scanf_s("%d", &num);
  17.  
  18. a = num / 100; //מאות
  19. b = num / 10 % 10;//עשרות
  20. c = num % 10;//יחידות
  21.  
  22. printf("Reversed digits: %d%d%d\n", c, b, a);
  23.  
  24. if (a > b)
  25. {
  26. if (a > c)
  27. {
  28. if (c > b)
  29. printf("Ascending digits: %d%d%d\n", b, c, a);
  30. else // a>b && b>c
  31. printf("Ascending digits: %d%d%d\n", c, b, a);
  32. }
  33. else // c>a && a>b
  34. printf("Ascending digits: %d%d%d\n", b, a, c);
  35. }
  36. else // b>a
  37. {
  38. if (c > b)
  39. {
  40. if (b > a)
  41. printf("Ascending digits: %d%d%d\n", a, b, c);
  42. else // c>b && a>b
  43. printf("Ascending digits: %d%d%d\n", b, a, c);
  44. }
  45. else //b>c && b>a
  46. if (a > c)
  47. printf("Ascending digits: %d%d%d\n", c, a, b);
  48. else // b>c && c>a
  49. printf("Ascending digits: %d%d%d\n", a, c, b);
  50. }
  51. break;
  52.  
  53. case 2: printf("Insert the coefficients of a linear equation.\n");*/
  54.  
  55. scanf_s("%d%d%d", &a, &b, &c);
  56.  
  57. d = (double)(b*b) - (4 * a * c);
  58. Root =(double) sqrt(d);
  59. X1 = (double)((-b) + Root) / (2 * a);
  60. X2 = (double)((-b) - Root) / (2 * a);
  61. Root2 = (double)sqrt((-c / a));
  62. //(sqrt((b * b) - (4 * a*c))) / (2 * a);
  63.  
  64. if ((d < 0) || (a == 0))
  65. {
  66. if ((b == 0) && (a == 0))
  67. printf("X has no solution.\n");
  68. else
  69. {
  70. if (a == 0)
  71. printf("X = %.1lf\n",(double)((-c) / b));
  72. else
  73. if (d == 0)
  74. printf("X= %.1lf\n", Root2);
  75. else // d<0
  76. printf("X has no solution.\n");
  77. }
  78. }
  79. else
  80. printf("X1= %.1lf X2= %.1lf\n", X1, X2);
  81. /*break;
  82.  
  83. case 3:
  84. break;
  85. }*/
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement