//c++
#include <iostream>
#include <cmath>
#include <ctime>
using namespace std;
signed main() {
srand(time(NULL));
setlocale(LC_ALL, "Rus");
int matrix[5][5];
long int pr = 1;
cout << "Сгенерированная матрица: " << endl;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
matrix[i][j] = rand() % 15;
cout << matrix[i][j] << " ";
if (matrix[i][j] % 2 != 0)
pr *= matrix[i][j];
}
cout << endl;
cout << "\nПроизведение нечетных элементов: " << pr << endl;
return 0;
Простейшее задание
Объяснение:
#include <functional>
#include <string>
#include <vector>
struct converter
{
std::function<double(double)> function;
std::string to;
};
int main()
std::vector<converter> table =
{[](double d) { return d; }, "kg"},
{[](double d) { return d / 1000 / 1000; }, "mg"},
{[](double d) { return d / 1000; }, "g"},
{[](double d) { return d * 100; }, "cnt" },
{[](double d) { return d * 1000; }, "tones" }
int ind = 0;
std::cin >> ind;
ind -= 1;
if (ind >= 0 && ind < table.size())
int m = 0;
std::cin >> m;
const converter& current = table[ind];
std::cout << "Result of converting " << m << " " << current.to << " is " << current.function(m) << " kg" << std::endl;
//c++
#include <iostream>
#include <cmath>
#include <ctime>
using namespace std;
signed main() {
srand(time(NULL));
setlocale(LC_ALL, "Rus");
int matrix[5][5];
long int pr = 1;
cout << "Сгенерированная матрица: " << endl;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
matrix[i][j] = rand() % 15;
cout << matrix[i][j] << " ";
if (matrix[i][j] % 2 != 0)
pr *= matrix[i][j];
}
cout << endl;
}
cout << "\nПроизведение нечетных элементов: " << pr << endl;
return 0;
}
Простейшее задание
Объяснение:
#include <iostream>
#include <functional>
#include <string>
#include <vector>
struct converter
{
std::function<double(double)> function;
std::string to;
};
int main()
{
std::vector<converter> table =
{
{[](double d) { return d; }, "kg"},
{[](double d) { return d / 1000 / 1000; }, "mg"},
{[](double d) { return d / 1000; }, "g"},
{[](double d) { return d * 100; }, "cnt" },
{[](double d) { return d * 1000; }, "tones" }
};
int ind = 0;
std::cin >> ind;
ind -= 1;
if (ind >= 0 && ind < table.size())
{
int m = 0;
std::cin >> m;
const converter& current = table[ind];
std::cout << "Result of converting " << m << " " << current.to << " is " << current.function(m) << " kg" << std::endl;
}
}