Mavzu: Massiv. Massiv tushunchasi. Bir o’lchovli massivlar. Reja: Massiv. Massiv tushunchasi


Izox: tasodifiy sonlar ichida manfiy sonlarning ham qatnashishini ixtiyor etsak


Download 28.99 Kb.
bet6/8
Sana31.01.2024
Hajmi28.99 Kb.
#1831658
1   2   3   4   5   6   7   8
Bog'liq
Massiv. Massiv tushunchasi Bir o’lchovli massivlar Bir o’lchovli-fayllar.org

Izox: tasodifiy sonlar ichida manfiy sonlarning ham qatnashishini ixtiyor etsak,

a[i] = 1050 - rand ( ); yoki a[i] = rand ( )-1000; deb yozish ham mumkin.
6-misol. 2 ta matritsa berilgan. Ularni o’zaro ko’paytirib yangi matritsa hosil qiling. Bu erda 1-matritsaning ustunlar soni 2-matritsaning satrlar soniga teng bo’lishi kerak.

Izox: i– 1-martitsaning ustunlari soni; j– 2-matritsaning satrlari soni;

k– kupaytirishlar soni

# include


# include
# include
# include
using namespace std;
int main ( )
{
{ srand ( time (0));
int a[3][3], b[3][3], c[3][3], i, j, k;
for (i=0; i<3; i++) for (j=0; j<3; j++)
a[i][j] = rand ( );
for (i=0; i<3; i++) for (j=0; j<3; j++)
b[i][j] = rand ( );
cout<<"\n"; for (i=0; i<3; i++)
{ for (j=0; j<3; j++) { c[i][j] = 0;
for (k=0; k<3; k++)
c[i][j] = c[i][j] + a[i][k]*b[k][j];
cout<<"C["}
cout << endl; }
getch ( );
} }


7-misol. A matritsani B vektorga ko’paytirish algoritmi. S i =
Izoh: matritsaning satrlari soni vektorning satrlariga teng bo’lishi kerak.

M asalan: 1 2 3 1

A = 4 5 6 B = 3
7 8 9 6

C1= 1*1+2*3+3*6 = 25

C2 = 4*1+5*3+6*6 = 55
C3 = 7*1+8*3+9*6 = 85
# include
# include
using namespace std;
int main ( )
{
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, b[3]= {1,3,6}, c[3], i, j;
cout<
for (i=0; i<3; i++)
{ c[i] = 0;
for (j=0; j<3; j++)
c[i] = c[i] + a[i][j] * b[j];
cout <<" C["<
getch ( );
}


8-misol. Matritsani transponirlash algoritmini tuzing. Matritsani transponirlash deb, ustun va satr elementlarini o’zaro o’rin almashtirishga aytiladi, ya`ni Aij = Bji

#
Berilgan matritsa:


1 2 3
4 5 6
7 8 9
Hosil bo’lgan matritsa:
1 4 7
2 5 8
3 6 9
include
# include
using namespace std;
int main ( )
{
int a[3][3] = {{1,2,3},{4,5,6},{7,8,9}}, b[3][3], i, j;
cout<
for ( i=0; i<3; i++)
{ for ( j=0; j<3; j++)
{ b[i][j] = a[j][i];
cout <<" b["<
cout << endl; }
getch ( );
}
9-misol. 3 ta qator va 4 ta ustunga ega A matritsa berilgan. Undagi eng katta elementni va uning indeksini topish, hamda o’sha qatorni massiv shaklida elementlarini ekranga chiqarish dasturini to’zish.

// programma max_indks


# include
# include
using namespace std;
int main ( )
{
int a[3][4]={{1,2,3,4},{4,5,6,7},{7,8,9,10}}, i, j, k, h, max;
int b[4];
max= a[0][0]; cout<
for (i=0; i<3; i++) for (j=0; j<4; j++)
{ if ( a[i][j] > max) { max = a[i][j]; k = i; h = j; } }
cout <<" Eng katta element max = "<
cout <<" "<
cout<
cout<<" Hamda o’sha qator elementlari";
for ( j=0; j<4; j++)
{ b[j] = a[k][j]; cout <<" b["<
getch ( );
}


Eng katta element max = 10; 3 - qator va 4 - ustundagi element ekan


Hamda o’sha qarot elementlari b[1]=7 b[2]=8 b[3]=9 b[4]=10

MAVZU: STRUKTURALAR MASSIVI. STRUKTURALARNI FUNKSIYALARGA UZATISH


Reja




  1. Download 28.99 Kb.

    Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8




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