cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Finding Greatest Common Divisor
Finding Greatest Common Divisor
Jan 2, 2015 at 5:27pm UTC
karankapoor
(1)
Is there a function or algorithm in stl in c++ which can help me find out the gcd of a vector ?
Last edited on
Jan 2, 2015 at 5:28pm UTC
Jan 2, 2015 at 5:53pm UTC
m4ster r0shi
(2201)
Yes. Assuming
v
is your vector and
gcd
a binary function, you can do:
std::accumulate(v.begin(), v.end(), v[0], gcd)
http://www.cplusplus.com/reference/numeric/accumulate/
Topic archived. No new replies allowed.