Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
HPC
hello-world
Commits
b56c9434
Commit
b56c9434
authored
Sep 23, 2017
by
Alejandro E. Rendon
Browse files
Vector Addition
parent
c8e94c11
Changes
2
Hide whitespace changes
Inline
Side-by-side
a.out
0 → 100755
View file @
b56c9434
File added
vec_add.cpp
0 → 100644
View file @
b56c9434
#include <iostream>
#include <string>
using
namespace
std
;
void
fillVec
(
int
*
vec
,
int
n
,
int
max
)
{
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
vec
[
i
]
=
rand
()
%
max
;
}
}
void
print
(
string
pref
,
int
*
vec
,
int
n
)
{
cout
<<
pref
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
cout
<<
vec
[
i
]
<<
" "
;
cout
<<
endl
;
}
void
add
(
int
*
a
,
int
*
b
,
int
*
c
,
int
n
)
{
for
(
int
i
=
0
;
i
<
n
;
i
++
)
c
[
i
]
=
a
[
i
]
+
b
[
i
];
}
int
main
(
int
argc
,
char
const
*
argv
[])
{
if
(
argc
<
2
)
cout
<<
"I need more inputs"
<<
endl
;
else
{
int
vec_size
=
stoi
(
argv
[
1
]);
int
*
a
,
*
b
,
*
c
;
a
=
(
int
*
)
malloc
(
vec_size
*
sizeof
(
int
));
b
=
(
int
*
)
malloc
(
vec_size
*
sizeof
(
int
));
c
=
(
int
*
)
malloc
(
vec_size
*
sizeof
(
int
));
fillVec
(
a
,
vec_size
,
10
);
fillVec
(
b
,
vec_size
,
10
);
print
(
"a = "
,
a
,
vec_size
);
print
(
"b = "
,
b
,
vec_size
);
add
(
a
,
b
,
c
,
vec_size
);
print
(
"c = "
,
c
,
vec_size
);
free
(
a
);
free
(
b
);
free
(
c
);
}
return
0
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment