#include <iostream>
#include <vector>
#include <numeric>
#include <random>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
using namespace std;
namespace ublas = boost::numeric::ublas;
void fill_matrix (ublas::matrix<int> & A)
{
random_device rng;
uniform_int_distribution<> gen (-10, 10);
for (int i = 0; i < A.size1(); i++)
for (int j = 0; j < A.size2(); j++)
A(i,j) = gen(rng);
}
int addition (int current_sum, int value)
if (value < 0 && value&1)
return current_sum + value;
return current_sum;
int main()
int n = 4;
ublas::matrix<int> A (n, n);
fill_matrix (A);
cout <<A <<endl;
int sum = accumulate (A.begin2(), A.end2() + A.size2() * (A.size1() - 1), 0,
addition);
cout <<sum <<endl;
Объяснение:
//1 - 2 задания
setlocale(LC_ALL, "Russian");
system("color A");
int A,a;
cout << "Введите число: ";
cin >> a;
while (a--)
cout << a << ' ';
cout << endl;
//2
cin >> A;
A -= !(A & 1) + 2;
while ((A += 2) < 1000)
cout << A << ' ';
//
//3 задание
for (int i = 1; i < 10; i += 2)
cout << i * i << ' ';
#include <iostream>
#include <vector>
#include <numeric>
#include <random>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
using namespace std;
namespace ublas = boost::numeric::ublas;
void fill_matrix (ublas::matrix<int> & A)
{
random_device rng;
uniform_int_distribution<> gen (-10, 10);
for (int i = 0; i < A.size1(); i++)
for (int j = 0; j < A.size2(); j++)
A(i,j) = gen(rng);
}
int addition (int current_sum, int value)
{
if (value < 0 && value&1)
return current_sum + value;
return current_sum;
}
int main()
{
int n = 4;
ublas::matrix<int> A (n, n);
fill_matrix (A);
cout <<A <<endl;
int sum = accumulate (A.begin2(), A.end2() + A.size2() * (A.size1() - 1), 0,
addition);
cout <<sum <<endl;
}
Объяснение:
#include <iostream>
using namespace std;
int main()
{
//1 - 2 задания
setlocale(LC_ALL, "Russian");
system("color A");
int A,a;
cout << "Введите число: ";
cin >> a;
while (a--)
cout << a << ' ';
cout << endl;
//2
cout << "Введите число: ";
cin >> A;
A -= !(A & 1) + 2;
while ((A += 2) < 1000)
{
cout << A << ' ';
}
}
//
//3 задание
#include <iostream>
using namespace std;
int main()
{
for (int i = 1; i < 10; i += 2)
cout << i * i << ' ';
}