Advertisement
Minecz

Untitled

Oct 21st, 2022
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. // vektory.cpp: Definuje vstupní bod pro aplikaci.
  2. //
  3.  
  4. #include "vektory.h"
  5. #include <stdio.h>
  6. #include <math.h>
  7.  
  8. using namespace std;
  9.  
  10.  
  11. void soucet(double v1[2], double v2[2], double v_result[2])
  12. {
  13. v_result[0] = v1[0] + v2[0];
  14. v_result[1] = v1[1] + v2[1];
  15. }
  16.  
  17. void rozdil(double v1[2], double v2[2], double v_result[2])
  18. {
  19. v_result[0] = v1[0] - v2[0];
  20. v_result[1] = v1[1] - v2[1];
  21. }
  22. void vector_magnitude(double v[2], double* magnitude)
  23. {
  24. *magnitude = sqrt(pow(v[0], 2) + pow(v[1], 2));
  25. }
  26.  
  27. void tisk(double v[2])
  28. {
  29. printf("[%.2f, %.2f]", v[0], v[1]);
  30. }
  31.  
  32. int main() {
  33. double v1[2];
  34. double v2[2];
  35. double v_result[2];
  36. double magnitude = 0;
  37. printf("Vektorova kalkulacka");
  38. printf("Zadej x1: ");
  39. scanf("%lf", &v1[0]);
  40. printf("Zadej y1: ");
  41. scanf("%lf", &v1[1]);
  42. printf("Zadej x2: ");
  43. scanf("%lf", &v2[0]);
  44. printf("Zadej y2: ");
  45. scanf("%lf", &v2[1]);
  46. printf("Co chcete s vektory delat? (soucet, rozdil): ");
  47. int choice;
  48. scanf("%d", &choice);
  49. switch (choice) {
  50. case 1:
  51. soucet(v1, v2, v_result);
  52. printf("Soucet vektoru: ");
  53. tisk(v_result);
  54. printf("Velikost vetoru: ");
  55. vector_magnitude(v_result, &magnitude);
  56. tisk(magnitude);
  57. break;
  58. case 2:
  59. rozdil(v1, v2, v_result);
  60. printf("Rozdil vektoru: ");
  61. tisk(v_result);
  62. printf("Velikost vetoru: ");
  63. vector_magnitude(v_result, &magnitude);
  64. tisk(magnitude);
  65. break;
  66. default:
  67. printf("Neznamy prikaz");
  68. return 1;
  69. }
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement