Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F78919316
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
Fri, Aug 23, 18:20
Size
744 B
Mime Type
text/x-c
Expires
Sun, Aug 25, 18:20 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20122205
Attached To
R9360 PCSC_git
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