• include using
  • 1. Kompyuter nima hardware, software Kompyuter nima




    Download 91,02 Kb.
    bet17/18
    Sana14.05.2024
    Hajmi91,02 Kb.
    #231246
    1   ...   10   11   12   13   14   15   16   17   18
    Bog'liq
    1. Kompyuter nima hardware, software-fayllar.org

    int maxSatr = 0;
    int maxSatrIndeksi = 0;
    // maxSatr ga birinchi satr elementlari yig`indisini ta’minlash
    for (int ustun = 0; ustun < USTUN_HAJM; ustun++) maxSatr+=matrix[0][ustun];
    for(int satr=1;satr< SATR_HAJM; satr++){
    int JoriySatrJami=0;
    for(int ustun=0;ustun< USTUN_HAJM; ustun++)
    JoriySatrJami+= matrix[satr][ustun];
    if(JoriySatrJami>maxSatr)
    { maxSatr = JoriySatrJami; maxSatrIndeksi = satr; }}
    cout<74.Ikki o’lchovli massivlarga oid masalalar(summing elements by column, random shuffling).


    1. (Tasodifiy aralashtirish) Bir o`lchovli massiv elementlarini tasodifiy aralashtirishni ko`rib chiqqanmiz. Xo`sh, ikki o`lchovli massiv elementlarini qanday qilib tasodifiy aralashtirish mumkin? Buni amalga oshirish uchun matrix[i][j] ning har bir elementi uchun tasodifiy i1 va j1 indekslari hosil qilinadi va matrix[i][j] element matrix[i1][j1] element bilan quyidagicha almashtiriladi:



    srand(time(0));
    for(int i=0;ifor(int j=0;jint i1=rand()%SATR_HAJM;
    int j1=rand()%USTUN_HAJM;// matrix[i][j] ni matrix[i1][j1] bilan almashtirish
    double temp=matrix[i][j];
    matrix[i][j]= matrix[i1][j1];
    matrix[i1][j1] = temp;}}
    75.Ikki o’lchovli massivlarni funksiyaga argument sifatida uzatish(passing two-dimensional arrays to functions).
    Ikki o`lchovli massiv funksiyaga yuborilganda, C++ da ustun hajmi funksiyada e’lon qilingan parametrga mos bo`lishi talab etiladi.
    13.1-kodli ro`yxatda ikki o`lchovli massiv elementlari yig`indisini qaytaruvchi funksiya berilgan.
    13.1-kodli ro`yxat. IkkiUlchovliMassivniYuborish.cpp
    #include
    using namespace std;
    constint USTUN_HAJM = 4; int sum (constint a[][USTUN_HAJM], int satrHajm) { int jami = 0;
    for (int satr = 0; satr < satrHajm; satr++) {
    for (int ustun = 0; ustun < USTUN_HAJM; ustun++) {
    jami += a[satr][ustun]; } } return jami; } intmain() {constint SATR_HAJM=3; int m[SATR_HAJM][USTUN_HAJM];

    Download 91,02 Kb.
    1   ...   10   11   12   13   14   15   16   17   18




    Download 91,02 Kb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    1. Kompyuter nima hardware, software Kompyuter nima

    Download 91,02 Kb.