Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,939 questions

51,876 answers

573 users

How to use partial_sum() and multiplies with int array in C++

1 Answer

0 votes
#include <iostream> 
#include <numeric>

using std::partial_sum;
using std::cout;  
using std::endl;

int main()
{
	int arr[] = { 1, 2, 3, 4, 5 };
	int r[5];

	/*
	r[0] = v1[0] = 1
	r[1] = v1[0] + v1[1] = 1 * 2 = 2
	r[2] = v1[0] + v1[1] + v1[2] = 1 * 2 * 3 = 6
	r[3] = v1[0] + v1[1] + v1[2] + v1[3] = 1 * 2 * 3 * 4 = 24
	r[4] = v1[0] + v1[1] + v1[2] + v1[3] + v1[4] = 1 * 2 * 3 * 4 * 5 = 120
	*/

	partial_sum(arr, arr + 5, r, std::multiplies<int>());
	
	for (int i = 0; i < 5; i++) 
		cout << r[i] << ' ';
	
	cout << endl;

	return 0;
}

/*
run:

1 2 6 24 120

*/

 



answered Apr 26, 2018 by avibootz

Related questions

...