Kommunikatsiyalarini rivojlantirish vazirligi muhammad al-xorazmiy nomidagi toshkent axborot texnologiyalari




Download 318,68 Kb.
Pdf ko'rish
Sana18.05.2024
Hajmi318,68 Kb.
#242569
Bog'liq
Algoritmlarni loyihalash. 1-dars.



O‘ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA 
 
KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI 
MUHAMMAD 
 
AL-XORAZMIY NOMIDAGI 
TOSHKENT AXBOROT TEXNOLOGIYALARI 
 
UNIVERSITETI 
 
 
 
Fakultet: Dasturiy injiniringi. 
 
 
 
 
 
 
 
 
 
 
 
 
 
ALGORITMLARNI LOYIHALASH
 
1-MAVZU: Massiv elementlarini saralash. Maksimal va minimal matritsa elementlarini 
aniqlash algoritmi. Matritsalarni ko'paytirish dasturi
 
 
 
 
Bajardi:
 
Sadirxojayev Xusanxoja
Guruh: 310-
22

 
 
Tekshirdi: Qo’ldoshev H. 
 
 
 
 
 
Amaliy ish - №1
 
15-variant
 
 
 
 
 


 
 
#include  
#include  
using namespace std; 
 
void printMatrix(const vector>& mat) { 
for (const auto& row : mat) { 
for (int elem : row) { 
cout << elem << " "; 

cout << endl; 

cout << endl; 

 
int main() { 
 
vector> A = {{3, 2, -1}, 
{0, -1, 2}, 
{5, 7, 1}}; 
vector> B = {{0, 3, -1}, 
{2, -1, 2}, 
{-3, 1, 4}}; 
 
// A + B 
cout << "A + B:" << endl; 
vector> sum(3, vector(3, 0)); 
for (int i = 0; i < 3; ++i) { 
for (int j = 0; j < 3; ++j) { 
sum[i][j] = A[i][j] + B[i][j]; 


printMatrix(sum); 
 
// A * B 
cout << "A * B:" << endl; 
vector> product(3, vector(3, 0)); 
for (int i = 0; i < 3; ++i) { 


for (int j = 0; j < 3; ++j) { 
for (int k = 0; k < 3; ++k) { 
product[i][j] += A[i][k] * B[k][j]; 



printMatrix(product); 
 
// A - B 
cout << "A - B:" << endl; 
vector> difference(3, vector(3, 0)); 
for (int i = 0; i < 3; ++i) { 
for (int j = 0; j < 3; ++j) { 
difference[i][j] = A[i][j] - B[i][j]; 


printMatrix(difference); 
 
// 3 * (A + B) 
cout << "3 * (A + B):" << endl; 
vector> scaledSum(3, vector(3, 0)); 
for (int i = 0; i < 3; ++i) { 
for (int j = 0; j < 3; ++j) { 
scaledSum[i][j] = 3 * (A[i][j] + B[i][j]); 


printMatrix(scaledSum); 
 
// (A * B - 2 * A) 
cout << "(A * B - 2 * A):" << endl; 
vector> intermediate(3, vector(3, 0)); 
for (int i = 0; i < 3; ++i) { 
for (int j = 0; j < 3; ++j) { 
intermediate[i][j] = A[i][j] * B[i][j] - 2 * A[i][j]; 


printMatrix(intermediate); 
 
// 3 * (A + B) * (A * B - 2 * A) 
cout << "3 * (A + B) * (A * B - 2 * A):" << endl; 
vector> finalResult(3, vector(3, 0)); 
for (int i = 0; i < 3; ++i) { 
for (int j = 0; j < 3; ++j) { 
for (int k = 0; k < 3; ++k) { 
finalResult[i][j] += scaledSum[i][k] * intermediate[k][j]; 





printMatrix(finalResult); 
 
return 0; 

 
 
 
 
 


PYTHON: 
 
def print_matrix(mat): 
for row in mat: 
print(*row) 
print() 
 
A = [[3, 2, -1], 
[0, -1, 2], 
[5, 7, 1]] 
 
B = [[0, 3, -1], 
[2, -1, 2], 
[-3, 1, 4]] 
 
# A + B 
print("A + B:") 
sum_matrix = [[A[i][j] + B[i][j] for j in range(3)] for i in range(3)] 
print_matrix(sum_matrix) 
 
# A * B 
print("A * B:") 
product_matrix = [[sum(A[i][k] * B[k][j] for k in range(3)) for j in range(3)] for i 
in range(3)] 
print_matrix(product_matrix) 
 
# A - B 
print("A - B:") 
difference_matrix = [[A[i][j] - B[i][j] for j in range(3)] for i in range(3)] 
print_matrix(difference_matrix) 
 
# 3 * (A + B) 
print("3 * (A + B):") 
scaled_sum_matrix = [[3 * (A[i][j] + B[i][j]) for j in range(3)] for i in range(3)] 
print_matrix(scaled_sum_matrix) 
 
# (A * B - 2 * A) 
print("(A * B - 2 * A):") 
intermediate_matrix = [[A[i][j] * B[i][j] - 2 * A[i][j] for j in range(3)] for i in 
range(3)] 
print_matrix(intermediate_matrix) 
 
# 3 * (A + B) * (A * B - 2 * A) 
print("3 * (A + B) * (A * B - 2 * A):") 


final_result_matrix = [[sum(scaled_sum_matrix[i][k] * intermediate_matrix[k][j] 
for k in range(3)) for j in range(3)] for i in range(3)] 
print_matrix(final_result_matrix) 
 
 
 
XULOSA 
 
Ushbu amaliy ishda С++ va Python tillarida yordamida ma'lumotlarni olishni 
ta’minlash bo‘yicha nazariy va amaliy bilim ko‘nikmalarni shakllantirdim va 
Matritsalar ustida amallar Matritsani songa ko‘paytirish Matritsalarni qo‘shish
Matritsalarni ko‘paytirishni o’rgandim 

Download 318,68 Kb.




Download 318,68 Kb.
Pdf ko'rish

Bosh sahifa
Aloqalar

    Bosh sahifa



Kommunikatsiyalarini rivojlantirish vazirligi muhammad al-xorazmiy nomidagi toshkent axborot texnologiyalari

Download 318,68 Kb.
Pdf ko'rish