mercMatvey4

Untitled

Dec 14th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. setlocale(LC_ALL,"");
  8. srand(time(0));
  9. int a[6][4];
  10. for (int i = 0; i < 4; i++)
  11. for (int j = 0; j < 6; j++)
  12. a[i][j]=rand()%10;
  13. cout << "Исходная матрица имеет вид : \n\n";
  14. for (int i = 0; i < 4; i++)
  15. {
  16. for (int j = 0; j < 6; j++)
  17. {
  18. cout << a[i][j] << " ";
  19. }
  20. cout << endl;
  21. }
  22. int Sum[4]={0,0,0,0}, Comp[4]={1,1,1,1};
  23. for (int i = 0; i < 4; i++)
  24. {
  25. for (int j = 0; j < 6; j++)
  26. {
  27. if ((i+j)%2!=0)
  28. {
  29. Sum[i] += a[i][j];
  30. Comp[i] *= a[i][j];
  31. }
  32. }
  33. }
  34. cout << "\nСумма нечетных элементов в каждой строке равна : " << Sum[0] << " " << Sum[1] << " " << Sum[2] << " " << Sum[3];
  35. cout << "\nПроизведение нечетных элементов в каждой строке равно : " << Comp[0] << " " << Comp[1] << " " << Comp[2] << " " << Comp[3] << "\n";
  36. }
Advertisement
Add Comment
Please, Sign In to add comment