Программное обеспечение (ПО)


Download 0.9 Mb.
Sana16.01.2022
Hajmi0.9 Mb.
#359889
Bog'liq
MASSIV1
Kurs ishi, Mustaqil ish, 7-seminar, Internetda ishlashni, sotsiologiya, structura

Massivler. Bir o’lshemli massivler

Massiov bul ne?

  • Массив –bul bir turge kiriwshi ha’m nbirdey attag’ elementlerdin’ tartiblengen topari. Massivta h’ar bir yacheyka o’zinin’ nimerne iye (indeks).
  • Talab etiledi:
  • 10000 o’zgeriwshini qalay kiritiw mumkin?
  • ?
  • yad ajiratiw
  • kerekli yacheykag’a berilgenlerdi jaziw
  • yacheykadan kerekli berilgenlerdi o’qiw

Yad ajiratiw (dag’azalaw)

  • int A[5];
  • double V[8];
  • bool L[10];
  • char S[80];
  • massiv = keste!
  • !
  • Elementler sani
  • const int N = 10;
  • int A[N];
  • ne ushin?
  • ?
  • Elementler noeri nolden baslanadi!
  • !
  • A[0], A[1], A[2], A[3], A[4]

Massiv elementi menen islew

  • 5
  • 10
  • 15
  • 20
  • 25
  • 0
  • 1
  • 2
  • 3
  • 4
  • A
  • massiv
  • 2
  • 15
  • Massiv elementi NOMERI
  • (INDEKSI)
  • A[0]
  • A[1]
  • A[2]
  • A[3]
  • A[4]
  • Massiv elementleri MA”NISLERI
  • A[2]
  • NOMERI (INDEKSI) 2

Massiv elementlerin qalay qayta islew mu’mkin?

  • Dag’azalaw:
  • Qayta islew:
  • const int N = 5;
  • int A[N];
  • // A[0] di qayta islew
  • // A[1] di qayta islew
  • // A[2] di qayta islew
  • // A[3] di qayta islew
  • // A[4] di qayta islew
  • Elementlerdi qayta islew:
  • i = 0;
  • // A[i] di qayta islew
  • i ++;
  • // A[i] di qayta islew i ++;
  • // A[i] di qayta islew i ++;
  • // A[i] di qayta islew i ++;
  • // A[i] di qayta islew
  • i ++;
  • Tsikldi qayta islew:
  • i = 0;
  • while ( i < N )
  • {
  • // A[i] di qayta islew i ++;
  • }
  • for tsikli
  • for( i = 0; i < N; i++ )
  • {
  • // A[i] di qayta islew }
  • Massiv elementlerin qalay qayta islew mu’mkin?

Massiv elementlerine ma’nis beriw

  • main()
  • {
  • const int N = 10;
  • int A[N];
  • int i;
  • for ( i = 0; i < N; i++ )
  • A[i] = i*i;
  • }
  • A[9]neshege ten’?
  • ?

Klaviaturadan elementlerdi kiritiw

  • Dag’azalaw:
  • Klaviaturadan kiritiw:
  • Ekrang’a shig’ariw:
  • const int N = 10;
  • int A[N];
  • for ( i = 0; i < N; i++ )
  • {
  • cout << "A[" << i << "]=";
  • cin >> A[i];
  • }
  • A[1] =
  • A[2] =
  • A[3] =
  • A[4] =
  • A[5] =
  • 5
  • 12
  • 34
  • 56
  • 13
  • cout >> “massiv A:\n";
  • for ( i = 0; i < N; i++ )
  • cout << A[i] << " ";
  • Probel ne ushin?
  • ?

Tosinarli sanlar menen toliqtiriw

  • for ( i = 0; i < N; i++ )
  • {
  • A[i] = irand ( 20, 100 );
  • cout << A[i] << " ";
  • }
  • Masele. massivti 20 dan 100 ge shekemgi tosinarli sanlar menen toliqtiriw.
  • int irand ( int a, int b )
  • {
  • return a + rand()% (b - a + 1);
  • }

Elementlerdi teriw

  • Uliwma sxemasi:
  • for ( i = 0; i < N; i++ )
  • {
  • ... // A[i]menen islew
  • }
  • Kereklilerin sanaw:
  • Misal. Massivta basketbolshilardin’ boylari jazilg’an. Olardan neshewi180 nen ulken ha’m190 sm dan kishi?
  • count = 0;
  • for ( i = 0; i < N; i++ )
  • if ( 180 < A[i] && A[i] < 190 )
  • count ++;

Elementlerdi teriw

  • Orta arifmetikaliq ma’nis:
  • int count, sum;
  • count = 0;
  • sum = 0;
  • for ( i = 0; i < N; i++ )
  • if ( 180 < A[i] && A[i] < 190 ) {
  • count ++;
  • sum += A[i];
  • }
  • cout << (float)sum / count;
  • Orta arifmetikaliq ma’nis
  • nege float?
  • ?

Massivta izlew

  • X elementine ten’lerin izlew:
  • i = 0;
  • while ( A[i] != X )
  • i ++;
  • cout << "A[" << i << "]=" << X;
  • Nesi jaman?
  • ?
  • i = 0;
  • while ( i < N && A[i] != X )
  • i ++;
  • if ( i < N )
  • cout << "A[" << i << "]=" << X;
  • else
  • cout << "Tabilmadi!";
  • Eger joq bolsa onda ne?
  • ?
  • i < N

Massivta izlew

  • nX = -1;
  • for ( i = 0; i < N; i++ )
  • if ( A[i] == X )
  • {
  • nX = i;
  • break;
  • }
  • if ( nX >= 0 )
  • cout << "A[" << nX << "]=" << X;
  • else
  • cout << "tabilmadi!";
  • Tabilsa tsikldan shig’iw:
  • break;
  • Tsikldan shigiw

Maksimal element

  • M = A[0];
  • for ( i = 1; i < N; i++ )
  • if ( A[i]> M )
  • M = A[i];
  • cout << M;
  • M = A[0]; nMax = 0;
  • for ( i = 1; i < N; i++ )
  • if ( A[i] > M ) {
  • M = A[i];
  • nMax = i;
  • }
  • cout << "A[" << nMax << "]=" << M;
  • nMax = 0;
  • nMax = i;
  • Neni jetilistiriw mu’mkin?
  • ?
  • Qalay onin’ nomerin tabiw?
  • ?

Maksimal element ha’m onin’ nomeri

  • Nomeri boyinsha ma’nisti tabiw mu’mkin!
  • !
  • nMax = 0;
  • for ( i = 1; i < N; i++ )
  • if ( A[i] > A[nMax] )
  • nMax = i;
  • cout << "A[" << nMax << "]=" << ;
  • A[nMax]
  • A[nMax]

Massiv reversi

  • 0
  • 1
  • 2
  • 3
  • N-4
  • N-3
  • N-2
  • N-1
  • 7
  • 12
  • 5
  • 8
  • 18
  • 34
  • 40
  • 23
  • 0
  • 1
  • 2
  • 3
  • N-4
  • N-3
  • N-2
  • N-1
  • 23
  • 40
  • 34
  • 18
  • 8
  • 5
  • 12
  • 7
  • «A’piwayi» sheshim:
  • for( i = 0; i < N ; i++ )
  • {
  • // A[i] ha’m A[N+1-i]orinlarin almastiriw
  • }
  • N/2
  • Ne jaman?
  • ?
  • Ortasinda toqtaw!

Massiv reversi

  • for ( i = 0; i < (N/2); i++ )
  • {
  • c = A[i];
  • A[i] = A[N-1-i];
  • A[N-1-i] = c;
  • }
  • c siz islew mu’mkinbe?
  • ?

Elementlerdi tsikl boyinsha jilistiriw

  • 0
  • 1
  • 2
  • 3
  • N-4
  • N-3
  • N-2
  • N-1
  • 12
  • 5
  • 8
  • 15
  • 34
  • 40
  • 23
  • 7
  • 0
  • 1
  • 2
  • 3
  • N-4
  • N-3
  • N-2
  • N-1
  • 7
  • 12
  • 5
  • 8
  • 18
  • 34
  • 40
  • 23
  • «A’piwayi» sheshim:
  • c = A[0];
  • for ( i = 0; i < N-1; i++ )
  • A[i] = A[i+1];
  • A[N-1] = c;
  • Ne jaman?
  • ?
  • ne ushin N-1?
  • ?

Kerekli elementlerdi tan’law

  • «A’piwayi» sheshim:
  • Ma’sele. A massivtin’ qandayda bir sha’rtti qanaatlandiratug’in elementlerin B massivke jaziw.
  • i di 0 den N-1 ushin islew
  • eger shart A[i] ushin orinlansa onda
  • B[i]:= A[i]
  • Ne jaman?
  • ?
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 12
  • 3
  • 34
  • 11
  • 23
  • 46
  • A
  • 12
  • ?
  • 34
  • ?
  • ?
  • 46
  • B
  • jup elementlerdi tan’law

Kerekli elementlerdi tan’law

  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 12
  • 3
  • 34
  • 11
  • 23
  • 46
  • A
  • 12
  • 34
  • 46
  • ?
  • ?
  • ?
  • B
  • jup elementlerdi tan’law
  • count = 0;
  • for ( i = 0; i < N; i++ )
  • if ( A[i] % 2 == 0 )
  • {
  • B[count] = A[i];
  • count ++;
  • }
  • for ( i = 0; i <  count ; i++ )
  • printf ( "%d ", B[i] );
  • count
  • Ekrang’a qalay shigadi?
  • ?
  • Eger A ha’m B – birdey massiv bolsa?
  • ?
  • B[count] = A[i];

Download 0.9 Mb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2022
ma'muriyatiga murojaat qiling