Untitled
#include <iostream> using namespace std; int main() { int tab[5][5] = { {10, 15, 20, 25, 30}, {35, 40, 45, 50, 55}, {60, 65, 70, 75, 80}, {85, 90, 95, 100, 105}, {110, 115, 120, 125, 130} }; int parzyste[25]; int nieparzyste[25]; int indeksParzyste = 0; int indeksNieparzyste = 0; for (int i = 0; i < 5; ++i) { for (int j = 0; j < 5; ++j) { if (tab[i][j] % 2 == 0) { parzyste[indeksParzyste++] = tab[i][j]; } else { nieparzyste[indeksNieparzyste++] = tab[i][j]; } } } cout << "Liczby parzyste: "; for (int i = 0; i < indeksParzyste; ++i) { cout << parzyste[i] << " "; } cout << endl; cout << "Liczby nieparzyste: "; for (int i = 0; i < indeksNieparzyste; ++i) { cout << nieparzyste[i] << " "; } cout << endl; return 0; }
Leave a Comment