Advertisement
mercMatvey4

Untitled

Dec 14th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 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 = 0, Comp = 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 += a[i][j];
  30. Comp *= a[i][j];
  31. }
  32. }
  33. }
  34. cout << "\nСумма нечетных элементов равна : " << Sum;
  35. cout << "\nПроизведение нечетных элементов равно : " << Comp << "\n";
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement