lemos Posted January 11, 2014 Report Share Posted January 11, 2014 Witam mam takie zadanie. Napisz program generujący tablicę o wymiarach 4x3, której elementy mają nastepujące wartości.puste 0 1 2 0 1 3 5 1 6 8 10 2 11 13 15 3 16 18 20Wartości elementów tablicy należy wyznaczyć, korzystając z ich indeksów: numeru wiersza i numeru kolumny.Nie mam pojęcia jak zrobić te indekst numeracyjne.Probowałem na wszelkie sposoby ten jest zrobiony poprawnie lecz nie zgadza się z poleceniem iż nie wygenerowałem tabeli 4x3 a 5x4.#include <iostream>#include <iomanip>#include <cstdlib>using namespace std;int main(){int tab[5][4]; tab[0][0] = 0; tab[0][1] = 0; tab[0][2] = 1; tab[0][3] = 2; tab[0][0] = 0; tab[1][1] = 1; tab[1][2] = 3; tab[1][3] = 5; tab[2][0] = 1; tab[2][1] = 6; tab[2][2] = 8; tab[2][3] = 10; tab[3][0] = 2; tab[3][1] = 11; tab[3][2] = 13; tab[3][3] = 15; tab[4][0] = 3; tab[4][1] = 16; tab[4][2] = 18; tab[4][3] = 20;for(int i=0;i<5;i++){ for (int j=0;j<4;j++){ cout << setw(5) << tab[i][j];}cout << endl;}system("pause");return 0;}A 2 kod bez indeksów z wygenerowana tabela 4x3 :#include <iostream>#include <iomanip>#include <cstdlib>using namespace std;int main(){int tab[4][3] = { {1,3,5}, {6,8,10}, {11,13,15}, {16,18,20} };for(int i=0;i<4;i++){ for (int j=0;j<3;j++){cout << setw(5) << tab[i][j];}cout << endl;}system("pause");return 0;}Prosze o pomoc. Z góry dziekuję. Quote Link to comment Share on other sites More sharing options...
Sevard Posted January 12, 2014 Report Share Posted January 12, 2014 (edited) W C++ indeksy zaczynają się od zera, więc w pierwszym przypadku powinieneś stworzyć tablicę 4x3 i ją wypełnić (po prostu pamiętaj, że n-ty wiersz ma indeks n-1). Edited January 12, 2014 by Sevard Quote Link to comment Share on other sites More sharing options...