wintest

МАТРИЦА: Мизерии с индески

Jan 14th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <clocale>
  3. #include <ctime>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. #define M 5
  9. #define N 5
  10.  
  11. void swapWithIndexes(int array[][N], size_t rows);
  12. void fillTheArray(int array[][N], size_t rows);
  13. void printTheArray(int array[][N], size_t rows);
  14.  
  15. int main(){
  16.     setlocale(LC_ALL, "Bulgarian");
  17.     srand(time(NULL));
  18.  
  19.     int array[M][N];
  20.     fillTheArray(array, M);
  21.     printTheArray(array, M);
  22.     cout << endl;
  23.     swapWithIndexes(array, M);
  24.     printTheArray(array, M);
  25.     return 0;
  26. }
  27. //Ж) промяна на матрицата, така че онези елементи от матрицата,
  28. //които съвпадат със сумата от индексите на елемента, се повдигнат на квадрат, //1 2 3
  29.                                                                               //4 5 6   //5 = (1,1) => 5 + ((1+1)^2)
  30.                                                                               //7 8 9  
  31. //а останалите се увеличат със сумата на индексите повдигната на квадрат;
  32.  
  33. //слагам стойности
  34.  
  35. void swapWithIndexes(int array[][N], size_t rows){
  36.     for (size_t i = 0; i < M; i++)
  37.     {
  38.         for (size_t j = 0; j < N; j++){
  39.             if (array[i][j] == (i + j)){
  40.                 array[i][j] = pow(array[i][j], 2);
  41.             }
  42.             else{
  43.                 array[i][j] += pow((i + j), 2);
  44.             }
  45.  
  46.         }
  47.     }
  48. }
  49. void fillTheArray(int array[][N], size_t rows){
  50.     for (size_t i = 0; i < M; i++)
  51.     {
  52.         for (size_t j = 0; j < N; j++){
  53.             array[i][j] = rand() % 5;
  54.  
  55.         }
  56.     }
  57. }
  58. //принтирам масив
  59. void printTheArray(int array[][N], size_t rows){
  60.     cout << "Оригиналната матрица е това : " << endl;
  61.  
  62.     for (size_t i = 0; i < M; i++)
  63.     {
  64.         for (size_t j = 0; j < N; j++){
  65.             cout << array[i][j] << "\t";
  66.         }
  67.         cout << endl;
  68.     }
  69. }
Add Comment
Please, Sign In to add comment