admin
|
|
« : Grudzień 13, 2010, 11:44:24 » |
|
Tablica jest pewną strukturą, którą można znaleźć praktycznie w każdym języku programowania. Tablicę można sobie wyobrazić jako szafę z szufladami. Do każdej szuflady można włożyć określony typ zmiennej. Aby można było dotrzeć do każdej danej w szufladzie, szuflady są ponumerowane. Numer szuflady pozwala ją łatwo odszukać. Każda tablica musi posiadać nazwę i liczbę komórek (czyli szuflad).
W przypadku Turbo Pascala deklaracja tablicy umieszczona jest w miejscu deklarowania zmiennych i wygląda następująco:
var tabliczka: array[1..10] of integer;nazwą tablicy jest tabliczka która posiada rozmiar 10 i można w niej umieścić liczby typu integer.Tablicę przedstawioną powyżej nazywamy tablicą jednowymiarową. Jest to tablica z jednym rzędem szuflad. Jeżeli chcemy wpisać wartość do tablicy należy wpisać np.: tabliczka[4]:=x;to do komórki (szuflady) o numerze 4 tablicy o nazwie tabliczka zostanie wpisana liczba x; Jeżeli musimy przechować więcej danych tworzymy tablice dwu i więcej wymiarowych. Przykład deklaracji tablicy dwu wymiarowej przedstawiono poniżej: var tabliczka: array[1..10,1..10] of integer;program storm; uses crt,dos; var tab: array[1..5] of integer;
begin tab[1]:=5; end.
|
|
« Ostatnia zmiana: Listopad 28, 2011, 10:50:39 wysłane przez admin »
|
Zapisane
|
|
|
|
admin
|
|
« Odpowiedz #1 : Grudzień 13, 2010, 12:06:08 » |
|
Zadanie 1. Proszę napisać program który do tablicy wpisze podane z klawiatury 5 imion i następnie wyświetli je na ekranie.
program tabl; uses crt,dos; var z: array[1..5] of string; v:integer; begin clrscr; for v:=1 to 5 do begin write('Podaj ',v,' imie: ');readln(z[v]); end; readkey; for v:=1 to 5 do begin writeln('Podales ',v,' imie: ',z[v]); end; readln; end.
|
|
« Ostatnia zmiana: Grudzień 13, 2010, 12:07:48 wysłane przez admin »
|
Zapisane
|
|
|
|
admin
|
|
« Odpowiedz #2 : Grudzień 20, 2010, 11:01:38 » |
|
Zadanie 2. Prosty matrix na tablicy. W programie do tablicy dopisywany jest pierwszy wiersz. Tablica jest następnie wyświetlana cyklicznie. powoduje to złudzenie przesuwania się na ekranie wierszy do dołu. Wprowadzenie spacji umożliwia przerwanie ciągu znaków.
program misi; uses crt,dos; var x,y,z:byte; tab3:array[1..39,1..20] of byte; tab4:array[1..39,1..20] of byte; tab5:array[1..39,1..20] of byte; tab6:array[1..39,1..20] of byte; begin randomize; clrscr;
for y:=1 to 20 do begin for x:=1 to 39 do begin tab3[x,y]:=48+random(11);end; end;
for y:=1 to 20 do begin writeln; for x:=1 to 39 do begin tab5[x,y]:=tab3[x,y]; if tab3[x,y]=58 then write( chr(32):2) else write( chr(tab3[x,y]):2); end;end;
repeat delay(100);clrscr; for y:=1 to 20 do begin for x:=1 to 39 do begin if y=1 then begin tab4[x,y]:=48+random(12);tab6[x,y]:=random(10);end else begin tab4[x,y]:=tab3[x,y-1];tab6[x,y]:=tab5[x,y-1];end; end; end;
for y:=1 to 20 do begin for x:=1 to 39 do begin tab3[x,y]:=tab4[x,y]; gotoxy(2*x,y);textcolor(green);
if (tab3[x,y]=58) or(tab3[x,y]=59) then write( chr(32)) else write( chr(tab3[x,y])); end;end; until keypressed; readkey; end.
|
|
|
Zapisane
|
|
|
|
admin
|
|
« Odpowiedz #3 : Styczeń 03, 2011, 09:35:08 » |
|
Zadanie 3. Proszę napisać program w którym zostaną zadeklarowane dwie tablice 10x10. Do każdej tablicy należy wpisać same 0. Następnie wyświetlić je na ekranie.
----------------------------------Nowe ----------------------------------------- program tab_3; uses crt,dos; var tab1: array[1..10,1..10] of byte; tab2: array[1..10,1..10] of byte; x,y: byte; begin clrscr; for x:=1 to 10 do begin for y:=1 to 10 do begin tab1[x,y]:=0; tab2[x,y]:=0; end;end;
gotoxy(5,5); write('Tablica 1'); for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(5+x,5+y); write(tab1[x,y]) end;end;
gotoxy(20,5); write('Tablica 2'); for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(20+x,5+y); write(tab2[x,y]) end;end;
readkey; end.
|
|
« Ostatnia zmiana: Styczeń 03, 2011, 09:49:48 wysłane przez admin »
|
Zapisane
|
|
|
|
admin
|
|
« Odpowiedz #4 : Styczeń 03, 2011, 10:41:51 » |
|
Zadanie 4. Utworzyć dwie tablice 10x10. Do każdej z tablic wpisać liczby 0. Wyświetlać naprzemiennie jedną tablicę w kolorze czerwonym drugą w białym.
program tab_3; uses crt,dos; var tab1: array[1..10,1..10] of byte; tab2: array[1..10,1..10] of byte; x,y: byte; begin clrscr; for x:=1 to 10 do begin for y:=1 to 10 do begin tab1[x,y]:=0; tab2[x,y]:=0; end;end;
repeat clrscr; textcolor(white); gotoxy(5,5); write('Tablica 1'); for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(5+x,5+y); write(tab1[x,y]) end;end; delay(200); clrscr; textcolor(red); gotoxy(20,5); write('Tablica 2'); for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(20+x,5+y); write(tab2[x,y]) end;end; delay(200); until keypressed;
readkey; end.
|
|
« Ostatnia zmiana: Styczeń 03, 2011, 10:49:30 wysłane przez admin »
|
Zapisane
|
|
|
|
admin
|
|
« Odpowiedz #5 : Styczeń 03, 2011, 11:04:28 » |
|
Zadanie 5. Dwie tabelki z poprzedniego zadania, są cały czas widoczne tylko zmieniają się naprzemiennie ich kolory.
program tab_5; uses crt,dos; var tab1: array[1..10,1..10] of byte; tab2: array[1..10,1..10] of byte; x,y,a: byte; begin clrscr; for x:=1 to 10 do begin for y:=1 to 10 do begin tab1[x,y]:=0; tab2[x,y]:=0; end;end; a:=0; repeat if a=0 then textcolor(white) else textcolor(red) ; gotoxy(5,5); write('Tablica 1'); for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(5+x,5+y); write(tab1[x,y]) end;end; if a=0 then textcolor(red) else textcolor(white) ; gotoxy(20,5); write('Tablica 2'); for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(20+x,5+y); write(tab2[x,y]) end;end; delay(200); a:=(a+1)mod 2; until keypressed;
readkey; end. --------------------------------NOWE -------------------------------- program tab_3; uses crt,dos; var tab1: array[1..10,1..10] of byte; tab2: array[1..10,1..10] of byte; x,y,a: byte; begin clrscr; for x:=1 to 10 do begin for y:=1 to 10 do begin tab1[x,y]:=0; tab2[x,y]:=0; end;end; a:=0; repeat if a=0 then textcolor(white) else textcolor(red) ; gotoxy(5,5); write('Tablica 1'); for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(5+x,5+y); write(tab1[x,y]) end;end; delay(100); if a=0 then textcolor(red) else textcolor(white) ; gotoxy(5,5); write('Tablica 2'); for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(5+x,5+y); write(tab2[x,y]) end;end; delay(100); a:=(a+1)mod 2; until keypressed;
readkey; end.
|
|
« Ostatnia zmiana: Styczeń 03, 2011, 11:31:06 wysłane przez admin »
|
Zapisane
|
|
|
|
admin
|
|
« Odpowiedz #6 : Styczeń 03, 2011, 11:34:04 » |
|
Zadanie 6. Program z zadania 5 przerobić tak, aby do tablic wpisywany był znak o kodzie ASCII wynoszącym 178.
program tab_6; uses crt,dos; var tab1: array[1..10,1..10] of char; tab2: array[1..10,1..10] of char; x,y,a: byte; begin clrscr; for x:=1 to 10 do begin for y:=1 to 10 do begin tab1[x,y]:=chr(178); tab2[x,y]:=chr(178); end;end; a:=0; repeat if a=0 then textcolor(white) else textcolor(red) ; gotoxy(5,5); write('Tablica 1'); for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(5+x,5+y); write(tab1[x,y]) end;end; delay(100); if a=0 then textcolor(red) else textcolor(white) ; gotoxy(5,5); write('Tablica 2'); for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(5+x,5+y); write(tab2[x,y]) end;end; delay(100); a:=(a+1)mod 2; until keypressed;
readkey; end.
|
|
« Ostatnia zmiana: Styczeń 03, 2011, 11:48:23 wysłane przez admin »
|
Zapisane
|
|
|
|
admin
|
|
« Odpowiedz #7 : Styczeń 03, 2011, 12:33:45 » |
|
Zadanie 7. Program wykorzystujący tablice jako macierz znakową. Napisany program wyświetla dużą cyfrę 2.
program tab_6; uses crt,dos; var tab1: array[1..10,1..10] of char; tab2: array[1..10,1..10] of char; x,y,a: byte; begin clrscr; for x:=1 to 10 do begin for y:=1 to 10 do begin tab1[x,y]:=' '; tab2[x,y]:=' '; end;end; tab1[3,4]:=chr(178);tab1[4,3]:=chr(178);tab1[5,3]:=chr(178);tab1[6,3]:=chr(178); tab1[7,4]:=chr(178);tab1[7,5]:=chr(178);tab1[7,6]:=chr(178);tab1[6,7]:=chr(178); tab1[5,8]:=chr(178);tab1[4,9]:=chr(178);tab1[3,10]:=chr(178);tab1[4,10]:=chr(178); tab1[4,10]:=chr(178);tab1[5,10]:=chr(178);tab1[6,10]:=chr(178);tab1[7,10]:=chr(178);
a:=0; repeat textcolor(white); gotoxy(5,5); write('Tablica 1'); for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(5+x,5+y); write(tab1[x,y]) end;end; delay(300);
gotoxy(5,5); write('Tablica 2'); for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(5+x,5+y); write(tab2[x,y]) end;end; delay(300); until keypressed;
readkey; end.
|
|
|
Zapisane
|
|
|
|
admin
|
|
« Odpowiedz #8 : Styczeń 03, 2011, 12:54:38 » |
|
Zadanie 8. Wyświetlane są naprzemiennie duże cyfry 1 i 2.
program tab_6_2; uses crt,dos; var tab1: array[1..10,1..10] of char; tab2: array[1..10,1..10] of char; x,y,a: byte; begin clrscr; for x:=1 to 10 do begin for y:=1 to 10 do begin tab1[x,y]:=' '; tab2[x,y]:=' '; end;end; tab1[3,4]:=chr(178);tab1[4,3]:=chr(178);tab1[5,3]:=chr(178);tab1[6,3]:=chr(178); tab1[7,4]:=chr(178);tab1[7,5]:=chr(178);tab1[7,6]:=chr(178);tab1[6,7]:=chr(178); tab1[5,8]:=chr(178);tab1[4,9]:=chr(178);tab1[3,10]:=chr(178);tab1[4,10]:=chr(178); tab1[4,10]:=chr(178);tab1[5,10]:=chr(178);tab1[6,10]:=chr(178);tab1[7,10]:=chr(178);
tab2[3,6]:=chr(178);tab2[4,5]:=chr(178);tab2[5,4]:=chr(178);tab2[6,3]:=chr(178); tab2[6,4]:=chr(178);tab2[6,5]:=chr(178);tab2[6,6]:=chr(178);tab2[6,7]:=chr(178); tab2[6,8]:=chr(178);tab2[6,9]:=chr(178);tab2[6,10]:=chr(178); tab2[7,4]:=chr(178);tab2[7,5]:=chr(178);tab2[7,6]:=chr(178);tab2[7,7]:=chr(178); tab2[7,8]:=chr(178);tab2[7,9]:=chr(178);tab2[7,10]:=chr(178);tab2[7,3]:=chr(178); a:=0; repeat textcolor(white); gotoxy(5,5); write('Tablica 1'); for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(5+x,5+y); write(tab1[x,y]) end;end; delay(500);
gotoxy(5,5); write('Tablica 2'); for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(5+x,5+y); write(tab2[x,y]) end;end; delay(500); until keypressed;
readkey; end.
|
|
|
Zapisane
|
|
|
|
admin
|
|
« Odpowiedz #9 : Styczeń 03, 2011, 13:13:15 » |
|
Zadanie 9. Modyfikacja liczby 2.
program tab_6; uses crt,dos; var tab1: array[1..10,1..10] of char; tab2: array[1..10,1..10] of char; x,y,a: byte; begin clrscr; for x:=1 to 10 do begin for y:=1 to 10 do begin tab1[x,y]:=' '; tab2[x,y]:=' '; end;end; tab1[3,4]:=chr(178);tab1[4,3]:=chr(178);tab1[5,3]:=chr(178);tab1[6,3]:=chr(178); tab1[7,4]:=chr(178);tab1[7,5]:=chr(178);tab1[7,6]:=chr(178);tab1[6,7]:=chr(178); tab1[5,8]:=chr(178);tab1[4,9]:=chr(178);tab1[3,10]:=chr(178);tab1[4,10]:=chr(178); tab1[4,10]:=chr(178);tab1[5,10]:=chr(178);tab1[6,10]:=chr(178);tab1[7,10]:=chr(178);
tab2[3,6]:=chr(178);tab2[4,5]:=chr(178);tab2[5,4]:=chr(178);tab2[6,3]:=chr(178); tab2[6,4]:=chr(178);tab2[6,5]:=chr(178);tab2[6,6]:=chr(178);tab2[6,7]:=chr(178); tab2[6,8]:=chr(178);tab2[6,9]:=chr(178);tab2[6,10]:=chr(178); tab2[7,4]:=chr(178);tab2[7,5]:=chr(178);tab2[7,6]:=chr(178);tab2[7,7]:=chr(178); tab2[7,8]:=chr(178);tab2[7,9]:=chr(178);tab2[7,10]:=chr(178);tab2[7,3]:=chr(178); a:=0; repeat textcolor(white); gotoxy(5,5); write('Tablica 1'); for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(15-x,5+y); write(tab1[x,y]) end;end; delay(500);
for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(x+5,5+y); write(tab1[x,y]) end;end; delay(500);
for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(x+5,18-y); write(tab1[x,y]) end;end; delay(500);
gotoxy(5,5); write('Tablica 2'); for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(5+x,5+y); write(tab2[x,y]) end;end; delay(500);
for x:=1 to 10 do begin for y:=1 to 10 do begin gotoxy(15-x,5+y); write(tab2[x,y]) end;end; delay(500);
until keypressed;
readkey; end.
|
|
|
Zapisane
|
|
|
|
admin
|
|
« Odpowiedz #10 : Styczeń 10, 2011, 09:11:29 » |
|
Zadanie X. Napisać program który do tablicy o nazwie A wpisze 10 liczb od 1 do 10. Następnie do tablicy B przepisze liczby z tablicy A powiększone o 3. -------------------------Rozwiązanie ----------------------------------- program X1; uses crt,dos; var A:array[1..10] of byte; B:array[1..10] of byte; z:byte;
begin
for z:=1 to 10 do begin A[z]:=z; end;
for z:=1 to 10 do begin B[z]:=A[z]+3; end; end. ----------------------------------Koniec---------------------------------------- Zadanie XX. Napisać program który do tablic imie , nazwisko wczyta podane z klawiatury 7 imion i nazwisk. Następnie poprosi o podanie liczby i po jej podaniu wyświetli imie i nazwisko ukryte w odpowiedniej komórce tabel : imie, nazwisko. ---------------------------------Początek ------------------------------------------------ program XX1; uses crt,dos; var imie:array[1..7] of string; nazwisko :array[1..7] of string; z:byte;
begin clrscr; for x:=1 to 7 do begin
write('Podaj ',z,' imie: ');readln(imie[z]); write('Podaj ',z,' nazwisko: ');readln(nazwisko[z]); end; write('Podaj liczbe: ');readln(z); write(imie[z],' ',nazwisko[z]);
readkey; end. -----------------------------Koniec-------------------------------------------
|
|
« Ostatnia zmiana: Styczeń 10, 2011, 10:51:48 wysłane przez admin »
|
Zapisane
|
|
|
|
admin
|
|
« Odpowiedz #11 : Styczeń 17, 2011, 08:50:27 » |
|
Zadanie 10. Napisać program w którym zadeklarowano tablicę A, B o wymiarach 10x10. Do tablicy A proszę wpisać literę A na głównej przekątnej, do tablicy B litery A w dwóch przekątnych. Pozostałe miejsca mają zostać zapełnione znakiem 0 (zero). -------------------------------------Rozwiązanie--------------------------------------------------- program tablica; uses crt,dos; var x,y,z:byte; A: array[1..10,1..10] of char; B: array[1..10,1..10] of char; begin clrscr; for x:=1 to 10 do begin for y:=1 to 10 do begin if (x=y) then A[x,y]:='A' else A[x,y]:='0'; if (x=y) or (x=11-y) then B[x,y]:='A' else B[x,y]:='0'; end;end;
for x:=1 to 10 do begin writeln; for y:=1 to 10 do begin write(A[x,y]:2); end;end; readkey; clrscr; for x:=1 to 10 do begin writeln; for y:=1 to 10 do begin write(B[x,y]:2); end;end; readkey; end.
|
|
« Ostatnia zmiana: Styczeń 17, 2011, 09:03:46 wysłane przez admin »
|
Zapisane
|
|
|
|
admin
|
|
« Odpowiedz #12 : Styczeń 17, 2011, 12:34:43 » |
|
Zadanie 11, z dwiema literkami.
program e; uses crt, dos; var x,y:byte; A: array[1..10,1..10] of byte; B: array[1..10,1..10] of byte; begin clrscr; for x:=1 to 10 do begin for y:=1 to 10 do begin A[x,y]:=0;end;end; A[2,2]:=1; A[3,2]:=1; A[4,2]:=1; A[5,2]:=1; A[5,3]:=1; A[5,4]:=1; A[4,5]:=1; A[3,6]:=1; A[2,7]:=1; A[3,7]:=1; A[4,7]:=1; A[5,7]:=1; for x:=1 to 10 do begin for y:=1 to 10 do begin B[x,y]:=0;end;end; B[4,1]:=1; B[5,1]:=1; B[6,1]:=1;B[7,1]:=1; B[4,2]:=1; B[4,3]:=1; B[4,4]:=1; B[5,4]:=1; B[6,4]:=1; B[7,4]:=1; B[8,5]:=1; B[8,6]:=1; B[8,7]:=1; B[8,8]:=1; B[7,9]:=1; B[6,10]:=1; B[5,10]:=1; B[4,10]:=1;
for y:=1 to 10 do begin writeln; for x:=1 to 10 do begin if A[x,y]=1 then begin gotoxy(35+x,y+10);write(chr(178));end; end;end;
readkey; clrscr; for y:=1 to 10 do begin writeln; for x:=1 to 10 do begin if B[x,y]=1 then begin gotoxy(35+x,y+10);write(chr(178));end; end;end;
readkey; end.
|
|
|
Zapisane
|
|
|
|
admin
|
|
« Odpowiedz #13 : Styczeń 17, 2011, 13:06:27 » |
|
program e; uses crt, dos; var x,y:byte; A: array[1..10,1..10] of byte; B: array[1..10,1..10] of byte; begin clrscr; for x:=1 to 10 do begin for y:=1 to 10 do begin A[x,y]:=0;end;end; A[2,2]:=1; A[3,2]:=1; A[4,2]:=1; A[5,2]:=1; A[5,3]:=1; A[5,4]:=1; A[4,5]:=1; A[3,6]:=1; A[2,7]:=1; A[3,7]:=1; A[4,7]:=1; A[5,7]:=1; for x:=1 to 10 do begin for y:=1 to 10 do begin B[x,y]:=0;end;end; B[4,1]:=1; B[5,1]:=1; B[6,1]:=1;B[7,1]:=1; B[4,2]:=1; B[4,3]:=1; B[4,4]:=1; B[5,4]:=1; B[6,4]:=1; B[7,4]:=1; B[8,5]:=1; B[8,6]:=1; B[8,7]:=1; B[8,8]:=1; B[7,9]:=1; B[6,10]:=1; B[5,10]:=1; B[4,10]:=1; repeat clrscr; for y:=1 to 10 do begin for x:=1 to 10 do begin if A[x,y]=1 then begin gotoxy(35+x,y+10);write(chr(178));end; end;end;
delay(100);clrscr; for y:=1 to 10 do begin for x:=1 to 10 do begin if B[x,y]=1 then begin gotoxy(35+x,y+10);write(chr(178));end; end;end; delay(100); until keypressed; readkey; end.
|
|
|
Zapisane
|
|
|
|
admin
|
|
« Odpowiedz #14 : Styczeń 24, 2011, 08:33:44 » |
|
program rysiu; uses crt,dos; var n: array[1..8,1..8] of byte; h:array[1..8,1..8] of byte; begin end. --------------------------------- Wersja rozwojowa------------------------------------------- program rysiu; uses crt,dos; var n: array[1..8,1..8] of byte; h:array[1..8,1..8] of byte; x,y: byte; begin for y:=1 to 8 do begin n[1,y]:=1;n[6,y]:=1; h[1,y]:=1;h[5,y]:=1;end; n[2,2]:=1;n[3,3]:=1;n[4,4]:=1; n[4,5]:=1;n[4,6]:=1;n[5,7]:=1; for x:=1 to 5 do h[x,4]:=1;
repeat for y:=1 to 8 do begin for x:=1 to 8 do begin gotoxy(10+x,1+y); if(n[x,y]=1) then write(chr(178)) else write(chr(32));end;end; delay(200); clrscr;
for y:=1 to 8 do begin for x:=1 to 8 do begin gotoxy(50+x,1+y); if(h[x,y]=1) then write(chr(178)) else write(chr(32));end;end; delay(200); clrscr;
until keypressed; readkey; end.
|
|
« Ostatnia zmiana: Styczeń 24, 2011, 09:38:39 wysłane przez admin »
|
Zapisane
|
|
|
|
|