Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Zahra_matrix
//g++ 5.4.0 // Created by Zahra Zaker Dehnavi #include <iostream> #include <cstdio> #include <ctime> using namespace std; void Sub_Add(int a[][3], int b[][3], int sub[][3], int add[][3]) { const int n = 3; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) { sub[i][j] = a[i][j] - b[i][j]; add[i][j] = a[i][j] + b[i][j]; } } int main() { srand(static_cast<size_t>(time(0))); const int n = 3; int a[n][n]; int b[n][n]; int sub[n][n]; int add[n][n]; /************* Phase 1 ************/ // Filling and printing matrix a with random numbers cout << "Matrix A:\n"; for (int (&i)[n] : a) { for (int (&j) : i) { j = rand() % 21; // [0, 20] cout.width(5); cout << j; } cout << endl; } // Filling and printing matrix b with random numbers cout << "\nMatrix B:\n"; for (int (&i)[n] : b) { for (int (&j) : i) { j = rand() % 21; // [0, 20] cout.width(5); cout << j; } cout << endl; } /************* Phase 2 ************/ Sub_Add(a, b, sub, add); /************* Phase 3 ************/ cout <<"\nSub[n][n] is:\n"; for (const int (&i)[n] : sub) { for (const int (&j) : i) { cout.width(5); cout << j; } cout << endl; } cout <<"\nAdd[n][n] is:\n"; for (const int (&i)[n] : add) { for (const int (&j) : i) { cout.width(5); cout << j; } cout << endl; } }
run
|
edit
|
history
|
help
0
Breakfast Menu
Factorial Inv wip
read_write_lock_acc
Nth max element in BST
Sieve of Eratosthenes
star print1
lambda capture
Dar
graph representation Adjacency List
on_off