Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SledMatrix.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- double random(double min, double max)
- {
- return (double)(rand()) / RAND_MAX*(max - min) + min;
- }
- double SledOfMatrix(double **Matrix, int stolbci, int stroki)
- {
- double sum = 0;
- for (int i = 0; i < stroki; i++) {
- for (int j = 0; j < stolbci; j++) {
- if (i == j)
- sum += Matrix[i][j];
- }
- }
- return sum;
- }
- int main()
- {
- int N = 5;
- srand(time(0));
- cout.precision(2);
- double **Array = new double*[N];
- for (int i = 0; i < N; i++) {
- Array[i] = new double[N];
- }
- for (int y = 0; y<N; y++) {
- for (int x = 0; x < N; x++)
- {
- Array[y][x] = random(0,20);
- cout << fixed << setw(4) << setprecision(2) << Array[y][x] << " ";
- }
- cout << endl;
- }
- cout << fixed << (double)SledOfMatrix(Array, 5, 5) << endl;;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement