Presentation is loading. Please wait.

Presentation is loading. Please wait.

DVODIMENZIONALNI NIZOVI (MATRICE) - Programming language C

Similar presentations


Presentation on theme: "DVODIMENZIONALNI NIZOVI (MATRICE) - Programming language C"— Presentation transcript:

1 DVODIMENZIONALNI NIZOVI (MATRICE) - Programming language C
Tehnička škola Takovska, 22 Pirot DVODIMENZIONALNI NIZOVI (MATRICE) - Programming language C - English language - Mathematics Struktura prezentacije 1. Čas - Opšti pojmovi, primeri i uvežbavanja 2. Čas - Osnovne operacije i njihova primena 3. Čas - Utvrđivanje, samostalna provera i smernice za dalji rad

2 ČAS 1. DEFINICIJA DVODIMENZIONALNOG NIZA - M A T R I C E
Back Next - Primeri matričnog (tabelarnog) uređenja podataka i primene ovakve strukture - Matematička definicija strukture i funkcionalnosti - Primena u vežbi na engleskom jeziku - Matrice u programiranju (Programski jezik C)

3 Primeri (Examples) Šahovska tabla
Back Next

4 Tablica množenja Back Next x 1 2 3 4 5 6 7 8 9 10 12 14 16 18 20 15 21 24 27 30 28 32 36 40 25 35 45 50 42 48 54 60 49 56 63 70 64 72 80 81 90 100

5 Matrični displej Back Next

6 Tastatura Back Next

7 I ko zna koliko još ... Back Next

8 Brainstorming !!! (Ideas, please…)
Navedite bez velikog razmišljanja svoj primer matrične (tabelarne) strukture podataka iz okoline ! na primer: Kalendar, Ukrštene reči, Lavirint, Periodični sistem hemijskih elementa, Šare pirotskog ćilima, ... Need HELP ? Click here !!! Back Next

9 Poveži sa nečim što već znaš !
Ređanjem više jednodimenzionalnih nizova podataka istih dimenzija i tipa podataka jedan do drugog dobijamo i drugu dimenziju . II dimenzija Back Next a1 a2 a3 . an a1 a2 a3 . an a1 a2 a3 . an . . . a1 a2 a3 . an I dimenzija

10 Struktura, osnovni pojmovi
Back Next Elementi matrice - presek svakog reda (i) i svake kolone (j) Kolone (COLUMNS) a11 a12 a13 a14 a15 ... a1n a21 a22 a23 a24 a25 a2n a31 a32 a33 a34 a35 a3n .. am1 am2 am3 am4 am5 amn Redovi (ROWS) aij

11 Terminologija (Basic terms)
(Rows) Redovi ili vrste su horizontale u matrici odnosno nizovi elemenata čiji je prvi indeks jednak (Columns) Kolone su vertikale u matrici odnosno nizovi elemenata čiji je drugi indeks jednak (Size) Veličina odnosno dimenzije matrice određene su brojem redova (m) i brojem kolona (n) i zapisuje se kao m x n Back Next

12 Skraćeni zapis matrice (Mathematics)
Back Next A = {aij}, i=1,m ; j= 1,n

13 Vežba - PREPOZNAJ SEBE U MATRICI
Spojiti klupe i formirati matricu dimenzija 5x6 (ili sličnu) Svaki učenik na pratećem obrascu u zadatim poljima upisuje svoju poziciju u učionici <click za dalje> Svaki učenik na pratećem obrascu u zadatom polju upisuje svoju visinu u cm <click za dalje> Neka ustanu svi učenici zadatog reda/kolone redom (1, 4, 2, 3, 5) <click za dalje> Neka ustanu redom svi učenici kod kojih je i>j, i<j, i=j Back Next

14 Vežba - OSMOSMERKA Back Next U narednoj vežbi uvežbavaju se osnovni pojmovi vezani za strukturu matrice. Vežba je na engleskom jeziku i podrazumeva znanja na temu "Nepravilni glagoli" odnosno njihovi oblici u infinitivu, prošlom vremenu i prošlom participu. Rezultate vežbe učenici upisuju u odgovarajuća polja na priloženom obrascu za praćenje časa. Ovi rezultati koriste se i u narednim vežbama.

15 Word Search Puzzle - Irregular verbs
1 2 3 ATE GOTTEN TAUGHT BROKEN GROWN THOUGHT DONE LET TORE 4 DRANK RIDDEN WORE 5 FED SLEPT WRITTEN 1 2 3 4 5 6 7 8 9 10 L D C N X K M A T E I R H O F U S G B P J W Z V Find the following irregular verbs in the MATRIX to the right. Give a list of (i,j) positions of the elements in the matrix. state whether the verb is in the past or past participle form (II and III column in the list of irregular verbs) supply the missing two. Example Been b (4,1) e (3,2) e (2,3) n (1,4) been –past participle be - was/were - been <click> <clear> Back Next

16 Word Search Puzzle - SOLUTION
Back Next 1 2 3 ATE GOTTEN TAUGHT BROKEN GROWN THOUGHT DONE LET TORE 4 DRANK RIDDEN WORE 5 FED SLEPT WRITTEN 1 2 3 4 5 6 7 8 9 10 L D C N X K M A T E I R H O F U S G B P J W Z V ATE (8,6) (7,6) (6,6) BROKEN (7,2) (6,2) (5,2) (4,2) (3,2) (2,2) DONE (6,9) (6,8) (6,7) (6,6) DRANK (4,6) (4,5) (4,4) (4,3) (4,2) FED (3,4) (2,3) (1,2) GOTTEN (9,8) (8,7) (7,6) (6,5) (5,4) (4,3) GROWN (10,7) (9,7) (8,7) (7,7) (6,7) LET (9,4) (8,5) (7,6) RIDDEN (2,7) (2,6) (2,5) (2,4) (2,3) (2,2) SLEPT (10,4) (9,4) (8,4) (7,4) (6,4) TAUGHT (1,10) (2,9) (3,8) (4,7) (5,6) (6,5) THOUGHT (7,10) (6,10) (5,10) (4,10) (3,10) (2,10) (1,10) TORE (5,1) (5,2) (5,3) (5,4) WORE (8,1) (8,2) (8,3) (8,4) WRITTEN (6,1) (6,2) (6,3) (6,4) (6,5) (6,6)(6,7)

17 Matrice u programskom jeziku C
Deklaracija matrice: tip Ident[m][n]; tip - tip podataka (Data type) elemenata matrice Ident - ime matrice m - broj redova n - broj kolona Primer: int M[5][6]; ili uz inicijalizaciju (dodelu početnih vrednosti elemenata matrice): float R[2][3] = { {2.3,4,0.45}, {3,3.4,5.6} }; Back Next

18 Matrice u programskom jeziku C
Specifičnost programskog jezika C: indeksi redova i kolona su iz opsega i = m-1 (ukupno m) j = n-1 (ukupno n) Primer: Ukoliko je deklarisana matrica na sledeći način: int M[5][6]; to znači da se indeksi vrste i kolone kreću u sledećim granicama: i = , j = Back Next

19 Pristup elementima u matrici
Back Next Pristup elementima ("upotrebi ili dodeli vrednost") matrice je operacija u kojoj koristimo određeni element/e matrice sa ciljem korišćenja njegove vrednosti u drugim naredbama/funkcijama ili dodele vrednosti datom elementu. Ident[i][j] Primer: int M[5][6], a, b=4; M[0][3] = b; M[2][5] = 25; a = M[0][3] + 2; if( a> M[2][5]) printf("Vrednost promenljive A je veća !!!);

20 Vežba - Napiši svoj program
Back Next Svoje rezultate iz osmosmerke prikazati programski po ugledu na zadati primer. Svoj program zapisati u zadato polje na pratećen obrascu. #include<stdio.h> void main() { int A[10][10] = {{...} ...}; printf("%d %d ...", A[4][5], A[4][6], ...); printf("Infinitiv glagola je: ...."); printf("Zadati glagol ... je iz 2/3 kolone."); }

21 ČAS 2 - OBILAZAK MATRICE Podsetimo se obilaska ("prolaza kroz") jednodimenzionalnih nizova za početak. Obilazak matrice je osnovna operacija u matrici. Realizuje se nadogradnjom algoritma obilaska nizova. Naučimo i uvežbajmo načine obilaska "red po red" i "kolonu po kolonu". Analizom primera upotrebe operacije obilaska matrice uočiti koje složenije operacije u matrici se zasnivaju na obilasku. Back Next

22 Obilazak jednodimenzionalnog niza (da počnemo od poznatog)
Ova operacija u nizu izvodi se tako što se redom pristupa svim elementima niza počevši od prvog prema poslednjem Pristup elementu niza znači korišćenje vrednosti datog elementa niza ili dodelu vrednosti datom elementu u nizu Pristup elementu je operacija koja se ponavlja onoliko puta koliko ima elemenata u nizu Back Next

23 Algoritamska / programska realizacija
Ponavljanje pristupa elementu niza realizujemo brojačkim ciklusom (petljom) Primer: for(i=0; i<n; i++) Niz[i] = i; ili printf("%d", Niz[i]); j = 1, M Niz[i] = i j = 1, M Niz[i] Back Next

24 Vežba - Obilazak niza podataka
Back Next Opis algoritma uz demonstraciju u I redu učenika: Prvog učenika u nizu proglašavamo najvišim in on stoji a ostali sede indeks niza (brojač) počinje od vrednosti 2 i završava se brojem učenika u I redu Upoređuju se visine do sada najvišeg učenika (koji stoji) i onaj do kog se stiglo indeksom (brojačem u petlji) koji takođe ustaje Ukoliko je dostignuti učenik viši od do sada najvišeg on ostaje da stoji indeks niza (brojač) se uvećava za 1 i ponavlja se korak 3 i 4 ukoliko je dostignut poslednji, učenik koji stoji je najviši i nalazi se na zadatoj poziciji

25 Vežba - "Play roles & demonstrate"
Using the following questions, answers and statements demonstrate the previously described algorithm. My position in the array is ___ I am ___ cm tall. What is your position in the array? How tall are you? I am taller and from now on : “I am the tallest in the array so far” Who is the next student in the array to compare with? Did we reach the end of the array? I am the tallest in the array. I am ___ cm tall and my position is ___ in the array! Back Next

26 Brainstorming !!! (Ideas, please!)
Kako proširiti prethodni algoritam da bi odredili najvišeg učenika u celom odeljenju (klupe čine matricu)? Koliko puta treba ponoviti prethodni algoritam za celu matricu? Šta i kako iskoristiti za to ponavljanje u programskoj realizaciji? Back Next

27 Obilazak matrice a11 a21 a31 am1 a12 a22 a32 am2 a13 a23 a33 am3 . a1n
Back Next U svakom prolazu kroz red indeks elemenata tog reda se kreće od 1 do n. Prelaskom u naredni red indeks elemenata se vraća na vrednost 1 i ponovo kreće do n. U svakom prolazu kroz kolonu indeks elemenata te kolone se kreće od 1 do m. Prelaskom u narednu kolonu indeks elemenata se vraća na vrednost 1 i ponovo kreće do m. "Row by row" <click> "Column by column" <click> a11 a21 a31 . am1 a12 a22 a32 . am2 a13 a23 a33 . am3 . a1n a2n a3n . amn a11 a21 a31 . am1 a12 a22 a32 . am2 a13 a23 a33 . am3 . a1n a2n a3n . amn

28 Primer upotrebe obilaska matrice (Tablica množenja)
Back Next Na primeru formiranja vrednosti elemenata matrice M(10,10) po ugledu na tablicu množenja demostrirati dva načina obilaska matrice: "red po red" i "kolonu po kolonu" "red po red" main () { int i, j, M[10][10]; for(i=0; i<10; i++) for(j=0; j<10; j++) M[i][j] = i*j; "kolona po kolona" main () { int i, j, M[10][10]; for(j=0; j<10; j++) for(i=0; i<10; i++) M[i][j] = i*j;

29 Algoritmi obilaska matrice Demonstracija u odeljenju-matrici
Koristeći dva učenika kao indekse i i j izvršiti prozivku učenika prethodno opisanim obilascima matrice! Učenici "indeksi" stoje sa strane (i) i ispred klupa (j) i prate promene koje u algoritmu čine brojačke promenljive i i j diktirane spoljnom i unutrašnjom for petljom. "Prozvani" učenik izgovara svoju visinu u cm. Uočiti i komentarisati dinamiku brojača unutrašnje i spoljne for petlje. Back Next

30 Vežba: Primer obilaska matrice (Broj pojavljivanja podatka u matrici)
Algorithm counting the given data P in the matrix using matrix iteration“row by row” Set the starting value of the counter No=0 (No=0 at the beginning means that maybe there is no given data in the matrix) Set the row counter of the matrix as i=1 and increase it in every iteration for 1 increment (i). If the bordering value is exceeded, go to the step 7. (i= n+1- the number of rows in the matrix + 1) Set an element counter within the row j=1 and increase it in every iteration for 1 increment (j). If the bordering value is exceeded , go to the step 6. (j=m+1 – the number of columns in the matrix plus 1) Compare the achieved element of the matrix with the given data M (i,j)=P? If that is the case, increase the number of occurrence - Increment (Br) Go back to step 3. Go back to step 2. Show the value of Br which represents the number of occurrence of the data N in the matrix. Answer the question: What could we count in the classroom using this method? Choose the most appropriate examples. Back Next

31 ČAS 3. - Proveri šta si naučio!
Obnovi stečena/uvežbana znanja i usvojene pojmove sa prethodnih časova radeći na tekstu na engleskom jeziku. Prepoznaj celine u kojima se ne snalaziš dobro! Vrati se u ličnom pratećem materijalu i podseti se rešenja! Pokušaj da prepoznaš najbitnije i kritički se osvrneš na moguće primene. Zapitaj se "Šta sledi?" i pokušaj da nađeš prave odgovore! Back Next

32 Pročitaj pažljivo tekst!
Back Next Two-dimensional data arrays- MATRICES Data are usually organized in the form of a table which suits the given data best. There is a rich variety of examples in our surroundings: school register, weekly attendance records, charts of weekly city temperatures, calendar, chess, “Reveal the pairs” game, results of laboratory measurements, etc. If we take several one–dimensional data arrays of the same length (number of elements) and write them one below the other, thus forming a table, we get the so called two-dimensional array or “an array of arrays” which is usually referred to as a matrix. The number of one-dimensional arrays (rows) represents the first dimension of the matrix and the number of elements in each of the arrays (column) represents the second dimension of the matrix. These numbers mxn are called matrix dimensions. The position (place) of the data within the matrix is determined by the number of the row and the number of the column of the particular data (intersection of the given column and the given row). These numbers are usually referred to as row subscript and column subscript according to the element subscript in one-dimensional array. All the matrix elements represent the data of the same type (uniformity of data type) and they carry the same name which is at the same time the name of the whole matrix. (uniqueness of the identifiers)

33 "Row by row" "Column by column"
Matrix of the dimensions mxn can be mathematically expressed in the following way: or the short form A=(aij), i=1,m j=1,n. The basic operation that can be performed in the matrix is the so called matrix iteration or passing round matrix. Essentially, this operation represents the access to all matrix elements “row by row” or “column by column”. In programming matrix iteration is used for solving the following tasks which are usually found when solving complex problems: Assigning values to matrix elements (using the keyboard or the assigning operator “=”) Matrix illustration Searching for the given data in the matrix Determining of the smallest/biggest matrix element Determining of sum/average value of the matrix elements Row/column sorting in the matrix "Row by row" "Column by column" Back Next

34 Test - Answer the Questions!
Back Next Odgovori na sledeća pitanja na osnovu prethodno pročitanog teksta i sadržaja na slajdovima. (Umesto testa na narednim slajdovima moguće je iskoristiti interaktivnu verziju testa u prilogu!)

35 Test - Part I Back Next How do we call the horizontal and vertical wholes in a matrix? What determines the position of every element in a matrix? Matrix elements are data of the __________ data type. Element subscripts in the matrix are ________ which determine in which ________ and which _______ the given element is positioned. Matrix dimensions are determined by (circle all the correct answers): The values of the neighboring elements in the matrix The number of columns in the matrix The position of elements in the bottom right corner of the matrix The number of rows in the matrix Element inscription order What does the uniformity of data type in a matrix mean? What determines a specific name (identifier) of every matrix element? If the matrix dimensions are mxn, what is the spectrum in which subscript of column j and subscript of row i occurs?

36 Test - Part II What is the short form of matrix in mathematics?
Back Next What is the short form of matrix in mathematics? Matrix iteration can also be called _________ matrix. In what ways can we perform matrix iteration? Which of the following examples of practical usage of matrix is not an adequate one and why? Chess Multiplication table Winning lottery numbers Calendar State some examples of “matrix iteration” which you can use for more complex operations. How many elements are there in Amxn matrix? In which part of the matrix are the elements for whose subscripts i=j? Elements of the same matrix row have the same subscript j. Yes / No?

37 Test - Part III Back Next I’m 194 cm tall and I am __________ in the array. (Circle the correct answer) a) tallest b) the tallest c) taller The position (place) of the data within the matrix is ___________ by intersection of the given column and the given row. (Circle the correct answer) a) determination b) determines c) determined If we take several one–dimensional data arrays of the same length and write them one below the other, we get the so called ________________. Is the following sentence grammatically correct? Why / Why not? Data is usually organized in the form of a table which suits the given data best. The number of elements in each of the arrays represents the second dimension of the matrix and it is called column / colon. Circle the correct answer. What’s the plural form of the noun matrix?

38 Part I - CORRECT ANSWERS
Horizontal = ROWS Vertical = COLUMNS ROW SUBSCRIPT AND COLUMN SUBSCRIPT Matrix elements are data of the SAME data type. Element subscripts in the matrix are NUMBERS which determine in which ROW and which COLUMN the given element is positioned. Matrix dimensions are determined by (circle all the correct answers): The values of the neighboring elements in the matrix The number of columns in the matrix The position of elements in the bottom right corner of the matrix The number of rows in the matrix Element inscription order All the matrix elements represent the DATA OF THE SAME TYPE. The NAME of the WHOLE MATRIX. j = m i = n Back Next

39 Part II - CORRECT ANSWERS
Back Next A=(aij), i=1,m j=1,n Matrix iteration can also be called PASSING ROUND MATRIX . “row by row” or “column by column” Which of the following examples of practical usage of matrix is not an adequate one and why? Chess Multiplication table Winning lottery numbers - one dimensional array Calendar Assigning values to matrix elements (using the keyboard or the assigning operator “=”) Matrix illustration Searching for the given data in the matrix Determining of the smallest/biggest matrix element Determining of sum/average value of the matrix elements Row/column sorting in the matrix m x n Main diagonal Elements of the same matrix row have the same subscript j. Yes / No ?

40 Part III - CORRECT ANSWERS
Back Next I’m 194 cm tall and I am the tallest in the array. (Circle the correct answer) a) tallest b) the tallest c) taller The position (place) of the data within the matrix is determined by intersection of the given column and the given row. (Circle the correct answer) a) determination b) determines c) determined If we take several one–dimensional data arrays of the same length and write them one below the other, we get the so called two–dimensional data arrays - matrix. Is the following sentence grammatically correct? Why / Why not? Data is usually organized in the form of a table which suits the given data best. The sentence is not correct because the noun data is in the plural form and it requires another form of the verb to be and that is are. Data are usually organized in the form of a table which suits the given data best. The number of elements in each of the arrays represents the second dimension of the matrix and it is called column / colon. Circle the correct answer. MATRICES

41 VEŽBA - Uklopi u celinu (Programiraj)
Koristeći delove programa "razbacane" po slajdu izborom i pravilnim ređanjem uklopi u program zadate namene: a) Prikaz elemenata matrice na ekranu b) Sumu elemenata matrice obilaskom matrice "kolonu po kolonu" Back Next

42 for(i=0; i<m; i++) (4) suma += A[i][j]; (2)
} (8) printf("\n"); (11) printf("Suma matrice =%d\n", suma); (1) int suma = 0; (13) main() { (9) { (10) } (6) printf("%5d", A[i][j]); (7) #include <stdio.h> (3) for(j=0; j<n; j++) (12) int i,j; (5) Back Next

43 Prikaz elemenata matrice na ekranu
#include <stdio.h> (3) main() { (9) int i,j; (5) for(i=0; i<m; i++) (4) { (10) for(j=0; j<n; j++) (12) printf("%5d", A[i][j]); (7) printf("\n"); (11) } (6) } (8) Back Next

44 Sumu elemenata matrice obilaskom matrice "kolonu po kolonu"
#include <stdio.h> (3) main() { (9) int suma = 0; (13) int i,j; (5) for(j=0; j<n; j++) (12) for(i=0; i<m; i++) (4) suma += A[i][j]; (2) printf("Suma matrice =%d\n", suma); (1) } (8) Back Next

45 Popuni evaluacioni formular! Hvala na iskrenim odgovorima!
Back Next

46 The end Back STOP


Download ppt "DVODIMENZIONALNI NIZOVI (MATRICE) - Programming language C"

Similar presentations


Ads by Google