krulas123 Temat założony przez niniejszego użytkownika |
Dodawanie i mnożenie talic wielowymiarowych » 2016-04-19 23:01:59 Witam, mogłby mi ktoś napisać jak sie dodaje i mnoży macierze/tablice wielowymiarowe. Patrzyłem w necie to jakieś tam losowe ze się podaje ile wierszy i ile kolumn, ale nie mogę nigdzie znaleźć jak zrobić to przy tablicach ustawionych na sztywno. Druga sprawa to taka ze jak dodam dwie jedynki to zeby wynik był 1 a nie 2, chodzi mi tutaj o to, żeby było tak jak w rachunku zdań w alternatywie. Tak faktycznie to nie są ani tablice ani tablice tylko grafy, kolejna i ostatnia sprawa to tam gdzie sa grafy połączone zeby wypisywało krawędzie np jak mam jedynkę na przecięciu 2,3 i 3,2 to żeby to 2,3;3,2 wypisało w jednej linii a pod spodem np 4,6;6,4 na razie mam tyle i nie wiem co dalej kombinować bo nie mogę się z tym dodawaniem grafów uporać #include "stdafx.h" #include<iostream> using namespace std;
int main() { cout << "Pierwszy" << endl; const int a = 6, b = 6; int tab1[ a ][ b ] = { { 0, 0, 0, 0, 1, 0 }, { 0, 0, 1, 0, 0, 1 }, { 0, 1, 0, 0, 0, 0 }, { 0, 0, 0, 0, 1, 0 }, { 1, 0, 0, 1, 0, 0 }, { 0, 1, 0, 0, 0, 0 } }; cout << tab1[ 0 ][ 0 ] << " " << tab1[ 0 ][ 1 ] << " " << tab1[ 0 ][ 2 ] << " " << tab1[ 0 ][ 3 ] << " " << tab1[ 0 ][ 4 ] << " " << tab1[ 0 ][ 5 ] << endl; cout << tab1[ 1 ][ 0 ] << " " << tab1[ 1 ][ 1 ] << " " << tab1[ 1 ][ 2 ] << " " << tab1[ 1 ][ 3 ] << " " << tab1[ 1 ][ 4 ] << " " << tab1[ 1 ][ 5 ] << endl; cout << tab1[ 2 ][ 0 ] << " " << tab1[ 2 ][ 1 ] << " " << tab1[ 2 ][ 2 ] << " " << tab1[ 2 ][ 3 ] << " " << tab1[ 2 ][ 4 ] << " " << tab1[ 2 ][ 5 ] << endl; cout << tab1[ 3 ][ 0 ] << " " << tab1[ 3 ][ 1 ] << " " << tab1[ 3 ][ 2 ] << " " << tab1[ 3 ][ 3 ] << " " << tab1[ 3 ][ 4 ] << " " << tab1[ 3 ][ 5 ] << endl; cout << tab1[ 4 ][ 0 ] << " " << tab1[ 4 ][ 1 ] << " " << tab1[ 4 ][ 2 ] << " " << tab1[ 4 ][ 3 ] << " " << tab1[ 4 ][ 4 ] << " " << tab1[ 4 ][ 5 ] << endl; cout << tab1[ 5 ][ 0 ] << " " << tab1[ 5 ][ 1 ] << " " << tab1[ 5 ][ 2 ] << " " << tab1[ 5 ][ 3 ] << " " << tab1[ 5 ][ 4 ] << " " << tab1[ 5 ][ 5 ] << endl << endl << endl; cout << "Drugi" << endl; int tab2[ a ][ b ] = { { 0, 1, 1, 0, 0, 0 }, { 1, 0, 1, 0, 0, 0 }, { 1, 1, 0, 0, 0, 1 }, { 0, 0, 0, 0, 1, 1 }, { 0, 0, 0, 1, 0, 1, }, { 0, 0, 1, 1, 1, 0 } }; cout << tab2[ 0 ][ 0 ] << " " << tab2[ 0 ][ 1 ] << " " << tab2[ 0 ][ 2 ] << " " << tab2[ 0 ][ 3 ] << " " << tab2[ 0 ][ 4 ] << " " << tab2[ 0 ][ 5 ] << endl; cout << tab2[ 1 ][ 0 ] << " " << tab2[ 1 ][ 1 ] << " " << tab2[ 1 ][ 2 ] << " " << tab2[ 1 ][ 3 ] << " " << tab2[ 1 ][ 4 ] << " " << tab2[ 1 ][ 5 ] << endl; cout << tab2[ 2 ][ 0 ] << " " << tab2[ 2 ][ 1 ] << " " << tab2[ 2 ][ 2 ] << " " << tab2[ 2 ][ 3 ] << " " << tab2[ 2 ][ 4 ] << " " << tab2[ 2 ][ 5 ] << endl; cout << tab2[ 3 ][ 0 ] << " " << tab2[ 3 ][ 1 ] << " " << tab2[ 3 ][ 2 ] << " " << tab2[ 3 ][ 3 ] << " " << tab2[ 3 ][ 4 ] << " " << tab2[ 3 ][ 5 ] << endl; cout << tab2[ 4 ][ 0 ] << " " << tab2[ 4 ][ 1 ] << " " << tab2[ 4 ][ 2 ] << " " << tab2[ 4 ][ 3 ] << " " << tab2[ 4 ][ 4 ] << " " << tab2[ 4 ][ 5 ] << endl; cout << tab2[ 5 ][ 0 ] << " " << tab2[ 5 ][ 1 ] << " " << tab2[ 5 ][ 2 ] << " " << tab2[ 5 ][ 3 ] << " " << tab2[ 5 ][ 4 ] << " " << tab2[ 5 ][ 5 ] << endl; int tab3[ a ][ b ] = tab1[ a ][ b ] + tab2[ a ][ b ]; system( "pause" ); return 0; }
|