[ create a new paste ] login | about

Link: http://codepad.org/RhTZ3S9F    [ raw code | output | fork ]

C++, pasted on Dec 20:
#include <iostream>
#include <algorithm>
#include <numeric>
#include <time.h>
using namespace std;
//////////////////////////////////////////////////////
void out(int *a,int n,int k);
void vin(int *a,int n);
void prod(int *a,int n,int k);
//////////////////////////////////////////////////////
int main()
{
	system("chcp 1251");
	int n=3,k=5;
	/*cout << "Введите количество строк: ";
	cin >> n;
	cout << "Введите количество столбцов: ";
	cin >> k;
	int *arr = new int[n*k];*/
	//int zero[2] = {0, 0};
	int arr[] = {0, 3, 3, 0, 1,
                        2, 0, 6, 1, 0,
                        1, 0, 10, 0, 2};
	//vin(arr,n*k);
	cout << "Массив:" << endl;
	out(arr,n,k);
	cout << "Произведения:" << endl;
	prod(arr,n,k);
	/*prod = accumulate(find_first_of(arr,arr+n,zero,zero+1)+1,
						find_end(arr,arr+n,zero,zero+1),
						1,
						multiplies<int>());
	cout << prod << endl;
	cout << *(find_first_of(arr,arr+n,zero,zero+1)+1)<< endl;
	cout << *(find_end(arr,arr+n,zero,zero+1)-1) << endl;*/
	getchar();
	return 0;
}
////////////////////////////////////////////////////////////
void out(int *a,int n, int k)
{
	int x = k-1;
	for(int i = 0; i < n*k;++i)
	{
		cout << a[i] << "  ";
		if(i == x)
		{
			cout << endl;
			x += k;
		}
	}
}
//------------------------------------------------------------
void vin(int *a,int n)
{
	srand(time(NULL));
	for(int i = 0; i < n; ++i)
		a[i] = rand()%10-5;
}
//-------------------------------------------------------------
void prod(int *a,int n,int k)
{
	int zero[2] = {0, 0};
	int x = k, i = 1;
	for(int i = 0; i < n; ++i)
	{
		cout << accumulate(find_first_of(a+i*x,a+(i+1)*x-1,zero,zero+1)+1,
						find_end(a+i*x,a+(i+1)*x-1,zero,zero+1),
						1,
						multiplies<int>()) << endl;
	}
	/*for(int i = 0; i < n;++i)
	{
		cout << *(find_first_of(a+i*x,a+(i+1)*x-1,zero,zero+1)+1) << "  ";
		cout << *find_end(a+i*x,a+(i+1)*x-1,zero,zero+1) << endl;
		//cout << *(a+i*x) << "  " << *(a+(i+1)*x-1) << endl;
	}*/
}


Output:
1
Disallowed system call: SYS_fork


Create a new paste based on this one


Comments: