online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <iostream> #include <iomanip> #include <cstdlib> #include <cmath> #include <ctime> #define ROWS 5 #define COLS 3 using namespace std; void fillMatrix(float * pMatrix, size_t rows, size_t cols) { for (size_t i = 0; i < rows ; i++) for (size_t j = 0; j < cols; j++) *(pMatrix + i * cols + j) = rand() % 800000 / 10000. - 40; return; } void printMatrix(float * pMatrix, size_t rows, size_t cols) { for (size_t i = 0; i < rows ; i++) { for (size_t j = 0; j < cols; j++) cout << setw(12) << *(pMatrix + i * cols + j); cout << endl; } return; } void replaceMatrix(float * pMatrix, size_t rows, size_t cols) { for(size_t i = 0; i < rows; i++) for(size_t j = 0; j < cols; j++) *(pMatrix + i * cols + j) *= acos((i + 1.) / (i + 1. + j + 1.)); return; } void amountElements(float * pMatrix, size_t rows, size_t cols, size_t & pos, size_t & neg) { for(size_t i = 0; i < cols; i++) { neg = pos = 0; for(size_t j = 0; j < rows; j++) *(pMatrix + j * cols + i) < 0 ? neg++ : pos++; cout << "\n Column #" << i + 1 << endl; cout << " Quantity of positive elements: " << pos << endl; cout << " Quantity of negative elements: " << neg << endl; } return; } int main(void) { float matr[ROWS][COLS]; // наша матрица size_t pos_amount; // счетчик положительных значений size_t neg_amount; // счетчик отрицательных значений srand( unsigned (time(NULL)) ); // запускаем рандомайзер // Сначала заполняем матрицу случайными значениями (любым удобным тебе способом) fillMatrix((float*)matr, ROWS, COLS); // Выводим её на экран cout << " Source matrix: " << endl; printMatrix((float*)matr, ROWS, COLS); // Заменяем значения матрицы согласно заданным условиям replaceMatrix((float*)matr, ROWS, COLS); // Выводим обновлённую матрицу на зкран cout << "\n Target matrix: " << endl; printMatrix((float*)matr, ROWS, COLS); // Находим количество положительных и отрицательных элементов // для каждого столбца матрицы и выводим на экран) amountElements((float*)matr, ROWS, COLS, pos_amount, neg_amount); return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue