Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102894843
ch-04-ex-03-solution.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Feb 25, 07:10
Size
697 B
Mime Type
text/x-c
Expires
Thu, Feb 27, 07:10 (1 d, 20 h)
Engine
blob
Format
Raw Data
Handle
24450527
Attached To
R1106 Programming Concept Rouaze
ch-04-ex-03-solution.cpp
View Options
/*
* chapter-04-exercise-03.cpp
*
* Dynamic memory for vectors
*
* Created on: Sep 24, 2012
* Author: Radu Popescu <radu.popescu@epfl.ch>
*/
#include <iostream>
int main(int argc, char* argv[])
{
// Do everything one billion times
for (int n = 0; n < 1000000000; ++n) {
// Allocate vectors
double* v = new double[3];
double* w = new double[3];
// Assign values
v[0] = 1.0; v[1] = 2.0; v[2] = 3.0;
w[0] = 4.0; w[1] = 5.0; w[2] = 6.0;
// Compute scalar product
double s = 0;
for (int i = 0; i < 3; ++i) {
s += v[i] * w[i];
}
std::cout << "The scalar product of v and w is: " << s << std::endl;
// Cleanup
delete[] v;
delete[] w;
}
return 0;
}
Event Timeline
Log In to Comment