Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. // DU03.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. char znak;
  7. double a[2], b[2], c[2];
  8. int temp1, temp2, temp3;
  9.  
  10. void soucet(double a[2], double b[2], double c[2])
  11. {
  12. c[0] = a[0] + b[0];
  13. c[1] = a[1] + b[1];
  14. }
  15.  
  16. void rozdil(double a[2], double b[2], double c[2])
  17. {
  18. c[0] = a[0] - b[0];
  19. c[1] = a[1] - b[1];
  20. }
  21.  
  22. void soucin(double a[2], double b[2], double c[2])
  23. //soucin komplexnich cisel se vypocte realna slozka * realna slozka - imaginarni slozka * imaginarni slozka - dle vzorce (ac - bd) + i(ad + bc)
  24. {
  25. c[0] = a[0] * b[0] - a[1] * b[1];
  26. c[1] = a[0] * b[1] + a[1] * b[0];
  27. }
  28.  
  29. void podil(double a[2], double b[2], double c[2])
  30. //pri podilu je treba vyloucit deleni nulou
  31. {
  32. if (b[0] == 0 && b[1] == 0)
  33. printf("Deleni 0 + 0j nelze.");
  34. else
  35. {
  36. temp1 = a[0] * b[0] + a[1] * b[1];
  37. temp2 = a[1] * b[0] - a[0] * b[1];
  38. temp3 = b[0] * b[0] + b[1] * b[1];
  39.  
  40. if (temp1%temp3 == 0 && temp2%temp3 == 0)
  41. {
  42. if (temp2 / temp3 >= 0)
  43. printf("Algebraicky tvar: %d + %dj", temp1 / temp3, temp2 / temp3);
  44. else
  45. printf("Algebraicky tvar: %d %dj", temp1 / temp3, temp2 / temp3);
  46. }
  47. else if (temp1%temp3 == 0 && temp2%temp3 != 0)
  48. {
  49. if (temp2 / temp3 >= 0)
  50. printf("Algebraicky tvar: %d + %d/%dj", temp1 / temp3, temp2, temp3);
  51. else
  52. printf("Algebraicky tvar: %d %d/%dj", temp1 / temp3, temp2, temp3);
  53. }
  54. else if (temp1%temp3 != 0 && temp2%temp3 == 0)
  55. {
  56. if (temp2 / temp3 >= 0)
  57. printf("Algebraicky tvar: %d/%d + %dj", temp1, temp3, temp2 / temp3);
  58. else
  59. printf("Algebraicky tvar: %d %d/%dj", temp1, temp3, temp2 / temp3);
  60. }
  61. else
  62. {
  63. if (temp2 / temp3 >= 0)
  64. printf("Algebraicky tvar: %d/%d + %d/%dj", temp1, temp3, temp2, temp3);
  65. else
  66. printf("Algebraicky tvar: %d/%d %d/%dj", temp1, temp3, temp2, temp3);
  67. }
  68. }
  69. }
  70.  
  71. void tisk(double c[2])
  72. {
  73. if (c[1] >= 0)
  74. {
  75. znak = '+';
  76. }
  77. else
  78. {
  79. znak = '-'; c[1] = c[1] * (-1);
  80. }
  81. printf("Algebraicky tvar: %.1lf %c %.1lfj \n", c[0], znak, c[1]);
  82. }
  83.  
  84.  
  85. int main()
  86. {
  87. printf("Zadej prvni realnou slozku:\n");
  88. scanf_s("%lf", &a[0]);
  89.  
  90. printf("Zadej prvni imaginarni slozku:\n");
  91. scanf_s("%lf", &a[1]);
  92.  
  93. printf("Zadej druhou realnou slozku:\n");
  94. scanf_s("%lf", &b[0]);
  95.  
  96. printf("Zadej druhou imaginarni slozku:\n");
  97. scanf_s("%lf", &b[1]);
  98.  
  99. printf("Zadej znamenko operace (+, -, *, /):\n");
  100. scanf_s(" %c", &znak);
  101. printf("\n");
  102.  
  103. switch(znak)
  104. {
  105. case '+':
  106. soucet(a, b, c);
  107. tisk(c);
  108. break;
  109.  
  110. case '-':
  111. rozdil(a, b, c);
  112. tisk(c);
  113. break;
  114.  
  115. case '*':
  116. soucin(a, b, c);
  117. tisk(c);
  118. break;
  119.  
  120. case '/':
  121. podil(a, b, c);
  122. break;
  123.  
  124. default:
  125. printf("Zadej pouze znamenko +, -, * nebo /");
  126. break;
  127. }
  128. getchar();
  129. return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement