Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL,"");
- srand(time(0));
- int a[6][4];
- for (int i = 0; i < 4; i++)
- for (int j = 0; j < 6; j++)
- a[i][j]=rand()%10;
- cout << "Исходная матрица имеет вид : \n\n";
- for (int i = 0; i < 4; i++)
- {
- for (int j = 0; j < 6; j++)
- {
- cout << a[i][j] << " ";
- }
- cout << endl;
- }
- int Sum[4]={0,0,0,0}, Comp[4]={1,1,1,1};
- for (int i = 0; i < 4; i++)
- {
- for (int j = 0; j < 6; j++)
- {
- if ((i+j)%2!=0)
- {
- Sum[i] += a[i][j];
- Comp[i] *= a[i][j];
- }
- }
- }
- cout << "\nСумма нечетных элементов в каждой строке равна : " << Sum[0] << " " << Sum[1] << " " << Sum[2] << " " << Sum[3];
- cout << "\nПроизведение нечетных элементов в каждой строке равно : " << Comp[0] << " " << Comp[1] << " " << Comp[2] << " " << Comp[3] << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment