• Funksiyaga matritsani uzatish
  • C++ dasturlash tili c tiliga asoslangan. C esa o'z navbatida b va bcpl tillaridan kelib chiqqan. Bcpl 1967 yilda Martin Richards tomonidan tuzilgan va operatsion sistemalarni yozish uchun mo'ljallangan edi




    Download 0,98 Mb.
    bet3/6
    Sana26.01.2024
    Hajmi0,98 Mb.
    #146468
    1   2   3   4   5   6
    Bog'liq
    Matritsalarni tashkil etish

    1.2. Matritsalar ustida amallar


    Masala. A(mxn) matritsa berilgan. Shu matritsa elementlar ini kirituvchi va ekranga jadval ko`rinishida chiqaruvchi programma tuzilsin.
    #include #include int main()
    {int m, n, a[10][10]; cout << "Satrlar sonini kiriting \nm=";cin >> m; cout << "Ustunlar sonini kiriting \nn=";cin >> n; cout <<"Massiv elementlarini kiriting \n"; for(int satr = 0; satr < m ; satr++) for(int ustun = 0; ustun < n; ustun++)
    { cout << "a[" << satr << "][" << ustun << "]="; cin >> a[satr][ustun]; } for(int satr = 0; satr < m; satr++) { for(int ustun = 0; ustun < n; ustun++) cout << a[satr][ustun] << "\t"; cout<<"\n"; } system ("pause"); return 0; }
    Funksiya parametri sifatida massivni jo'natish va funksiya natijasi sifatida massivni olish ham mumkin. Funksiyaga matritsani uzatishda matritsa nomi bilan uning satrlar va ustunlar sonini ham jo'natish kerak bo'ladi. Funksiyada massivdan foydalanishni bir necha xil usuli bor, shularning ba'zilari bilan tanishamiz.

    Funksiyaga matritsani uzatish


    #include #include void matrix_print(int a[10][10], int m, int n)
    {
    // matritsani jadval shaklida chiqarish for (int i = 0; i < m; i++)
    { for (int j = 0; j < n; j++)
    { cout << a[i][j] << "\t";
    }
    cout << "\n";
    } } int satr_max(int a[], int n)
    {
    // massivning eng katta elementini aniqlash int max = a[0]; for (int i = 1; i < n; i++) if (max < a[i]) max = a[i]; return max; } int main() { int m, n, a[10][10]; cout << "Satrlar sonini kiriting \nm="; cin >> m; cout << "Ustunlar sonini kiriting \nn="; cin >> n; cout <<"Massiv elementlarini kiriting \n"; for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) cin >> a[i][j]; cout << "Kiritilgan matritsa\n";
    //funksiyaga matritsa, satrlar va ustunlar soni jo'natiladi matrix_print(a, m, n); for (int i = 0; i < m; i++)
    {
    // funksiyaga i-satrning 0-elementi adresini // va elementlar sonini jo'natamiz cout << i << "-satrning eng kattasi=" << satr_max(&a[i][0], n); cout << endl; } return 0;
    system ("pause");
    }

    Download 0,98 Mb.
    1   2   3   4   5   6




    Download 0,98 Mb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    C++ dasturlash tili c tiliga asoslangan. C esa o'z navbatida b va bcpl tillaridan kelib chiqqan. Bcpl 1967 yilda Martin Richards tomonidan tuzilgan va operatsion sistemalarni yozish uchun mo'ljallangan edi

    Download 0,98 Mb.