Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <clocale>
- #include <ctime>
- #include <cmath>
- using namespace std;
- #define M 5
- #define N 5
- void swapWithIndexes(int array[][N], size_t rows);
- void fillTheArray(int array[][N], size_t rows);
- void printTheArray(int array[][N], size_t rows);
- int main(){
- setlocale(LC_ALL, "Bulgarian");
- srand(time(NULL));
- int array[M][N];
- fillTheArray(array, M);
- printTheArray(array, M);
- cout << endl;
- swapWithIndexes(array, M);
- printTheArray(array, M);
- return 0;
- }
- //Ж) промяна на матрицата, така че онези елементи от матрицата,
- //които съвпадат със сумата от индексите на елемента, се повдигнат на квадрат, //1 2 3
- //4 5 6 //5 = (1,1) => 5 + ((1+1)^2)
- //7 8 9
- //а останалите се увеличат със сумата на индексите повдигната на квадрат;
- //слагам стойности
- void swapWithIndexes(int array[][N], size_t rows){
- for (size_t i = 0; i < M; i++)
- {
- for (size_t j = 0; j < N; j++){
- if (array[i][j] == (i + j)){
- array[i][j] = pow(array[i][j], 2);
- }
- else{
- array[i][j] += pow((i + j), 2);
- }
- }
- }
- }
- void fillTheArray(int array[][N], size_t rows){
- for (size_t i = 0; i < M; i++)
- {
- for (size_t j = 0; j < N; j++){
- array[i][j] = rand() % 5;
- }
- }
- }
- //принтирам масив
- void printTheArray(int array[][N], size_t rows){
- cout << "Оригиналната матрица е това : " << endl;
- for (size_t i = 0; i < M; i++)
- {
- for (size_t j = 0; j < N; j++){
- cout << array[i][j] << "\t";
- }
- cout << endl;
- }
- }
Add Comment
Please, Sign In to add comment