-
Notifications
You must be signed in to change notification settings - Fork 0
/
5_vectors2.cpp
41 lines (33 loc) · 1.09 KB
/
5_vectors2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* Calculating the vector length using vector
written by Tariq Ridwan: 👉 https://tariqridwan.github.io/
Universitat Politècnica de Catalunya, Barcelona */
#include<iostream>
#include<string>
#include<cmath>
// using namespace std; //
double vector_length(double x, double y, double z);
int main()
{
double L;
double sample_vector[3][1];
std::string write_intro;
write_intro = "Calculating Vector length\n";
std::cout << write_intro;
std::cout << "What is the value of x?" << std::endl;
std::cin >> sample_vector[0][0];
std::cout << "What is the value of y\n";
std::cin >> sample_vector[1][0];
std::cout << "What is the value of z?" << std::endl;
std::cin >> sample_vector[2][0];
// calculate
std::cout << "So the Vector's Length is:" << std::endl;
L = vector_length(sample_vector[0][0],sample_vector[1][0],sample_vector[2][0]);
std::cout << L << std::endl;
return 0;
}
double vector_length(double x, double y, double z)
{
double result; // int or double
result = sqrt( pow(x,2.0) + pow(y,2.0) + pow(z,2.0));
return result;
}