Mavzu: Funksiya va massivlar. Misol


Download 0.58 Mb.
Sana17.06.2023
Hajmi0.58 Mb.
#1544694
Bog'liq
Shomirzayev Abdujalil Dasturlash asoslari.


Mavzu: Funksiya va massivlar.
Misol: Berilgan n x m o‘lchamdagi matrisaning k - ustundagi eng katta elementi topilsin .
Dastur kodi:
#include
using namespace std;
int K_ustun_max(int n,int k,int **a)
{
int max=a[0][k];
for(int i=1;iif(max<=a[i][k]) max=a[i][k];
return max;
}
int main()
{
int n, m, k, l;
int **a;
cout << "Matritsaning satrlar soni=";
cin >> n;
cout << "Matritsaning ustunlar soni=";
cin >> m;
// matritsani hosil qilish
a = new int *[n];
for (int i = 0; i < n; i++)
a[i] = new int[m];
srand(time(0));
// matritsa elementlari qiymatlarini tanlab olish
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
a[i][j] = rand() % 90 + 10;
// matritsani chop etish
cout << "\nMatritsa ko'rinishi:\n";
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
cout << a[i][j] << " ";
cout << endl;
}
do
{
cout << "\nk-ustun nomerini kiriting="; cin >> k;
} while (k < 0 || k >= m);
cout << k << "-ustun maximal elementi =" << K_ustun_max(n, k, a);
for (int i = 0; i < n; i++)
delete[]a[i];
delete[]a;
system(“pause”);
return 0;
}

Dastur natijasi





Download 0.58 Mb.

Do'stlaringiz bilan baham:




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