Bajardi: Bekpo’latov Ahrorbek


Download 154.2 Kb.
Sana19.02.2023
Hajmi154.2 Kb.
#1214987
Bog'liq
variant 6


MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI
UNIVERSITETI




Amaliy ish

Bajardi: Bekpo’latov Ahrorbek


TOSHKENT 2023





Vazifalar

6

n x m o‘lchamli matrisa berilgan. Matrisaning eng katta elementi joylashgan ustunni o‘chiring.



#include
using namespace std;

int main()


{
int n, m;
cout << "Matrisa o'lchami: \n";
cout << "n = ";
cin >> n;
cout << "m = ";
cin >> m;

int matrix[n][m];


int max_val = INT_MIN;
int max_col;

cout << "Matrisa elementlarini kiriting:" << endl;


for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
matrix[i][j] = rand() % 100 + 1;
if (matrix[i][j] > max_val)
{
max_val = matrix[i][j];
max_col = j;
}
}
}

cout << "Matrisa:" << endl;


for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cout << matrix[i][j] << " ";
}
cout << endl;
}
cout << endl;


for (int i = 0; i < n; i++)
{
for (int j = max_col; j < m - 1; j++)
{
matrix[i][j] = matrix[i][j + 1];
}
}

m--;

cout << "\nYangi matrisa:" << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cout << matrix[i][j] << " ";
}
cout << endl;
}


return 0;
}

2 topshiriq.




Funksiya

6

O‘nlik sanoq sistemasidagi a sonni ikkilik sanoq sistemasiga o‘tkazuvchi dastur tuzing


#include
using namespace std;

int main()


{
int a;
cout << "O'nlik sanoq sistemasidagi sonni kiriting: ";
cin >> a;

int b[32];


int i = 0;


while (a > 0)
{
b[i] = a % 2;
a /= 2;
i++;
}

cout << "Ikkilik sanoq sistemasidagi qiymat: ";


for (int j = i - 1; j >= 0; j--)
{
cout << b[j];
}
cout << endl;


return 0;
}




3 –topshiriq.



Parametrli funksiyalar

6

Yig’indini topadigan butun son tipidagi SumRange(A, B) funksiyasini yozing. A dan B gacha bo‘lgan barcha butun sonlar (A va B butun sonlar). Agar A > B bo‘lsa, funktsiya 0 ni qaytaradi. Bu funksiyadan foydalanib, A, B, C raqamlari berilgan bo‘lsa, A dan B gacha va B dan C gacha bo‘lgan sonlar yig’indisini toping.


#include
using namespace std;

int SumRange(int A, int B)


{
if (A > B)
{
return 0;
}
int sum = 0;
for (int i = A; i <= B; i++)
{
sum += i;
}
return sum;
}

int main()


{
int A, B, C;
cout << "A ni kiriting: ";
cin >> A;
cout << "B ni kiriting: ";
cin >> B;
cout << "C ni kiriting: ";
cin >> C;

int sum = SumRange(A, B) + SumRange(B, C);


cout << A << " dan " << B << " gacha va " << B << " dan " << C << " gacha sonlar yig'indisi: " << sum << endl;


return 0;
}


Download 154.2 Kb.

Do'stlaringiz bilan baham:




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