Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // vektory.cpp: Definuje vstupní bod pro aplikaci.
- //
- #include "vektory.h"
- #include <stdio.h>
- #include <math.h>
- using namespace std;
- void soucet(double v1[2], double v2[2], double v_result[2])
- {
- v_result[0] = v1[0] + v2[0];
- v_result[1] = v1[1] + v2[1];
- }
- void rozdil(double v1[2], double v2[2], double v_result[2])
- {
- v_result[0] = v1[0] - v2[0];
- v_result[1] = v1[1] - v2[1];
- }
- void vector_magnitude(double v[2], double* magnitude)
- {
- *magnitude = sqrt(pow(v[0], 2) + pow(v[1], 2));
- }
- void tisk(double v[2])
- {
- printf("[%.2f, %.2f]", v[0], v[1]);
- }
- int main() {
- double v1[2];
- double v2[2];
- double v_result[2];
- double magnitude = 0;
- printf("Vektorova kalkulacka");
- printf("Zadej x1: ");
- scanf("%lf", &v1[0]);
- printf("Zadej y1: ");
- scanf("%lf", &v1[1]);
- printf("Zadej x2: ");
- scanf("%lf", &v2[0]);
- printf("Zadej y2: ");
- scanf("%lf", &v2[1]);
- printf("Co chcete s vektory delat? (soucet, rozdil): ");
- int choice;
- scanf("%d", &choice);
- switch (choice) {
- case 1:
- soucet(v1, v2, v_result);
- printf("Soucet vektoru: ");
- tisk(v_result);
- printf("Velikost vetoru: ");
- vector_magnitude(v_result, &magnitude);
- tisk(magnitude);
- break;
- case 2:
- rozdil(v1, v2, v_result);
- printf("Rozdil vektoru: ");
- tisk(v_result);
- printf("Velikost vetoru: ");
- vector_magnitude(v_result, &magnitude);
- tisk(magnitude);
- break;
- default:
- printf("Neznamy prikaz");
- return 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement