• //Haftalik o’rtacha tempraturani hisoblash dasturi include include using namespace std;
  • include using namespace std; int main () { int x[ ] = {1, 2, 56, 78, -7, -45, 34, 12, 9, -1}; int s=0, n=0;
  • include include using namespace std; int main () { int x[10], s=0, i, n=0;
  • Bir o’lchovli massivlar




    Download 18,54 Kb.
    bet2/2
    Sana12.12.2023
    Hajmi18,54 Kb.
    #117272
    1   2
    Bog'liq
    Bir o’lchovli massivlar

    Massivni e`lon qilish:
    char ch[4]={‘a’, ‘b’, ‘c’, ‘d’}; //simvolli massiv
    int in[6]={10, 20, 30, 40}; // butun sonli massiv
    char str[]="abcd"; //satr uzunligi 5 ga teng, chunki uning oxiriga ‘\0’ belgisi qo’shiladi
    char str[]={'a', 'b', 's', 'd'}; // YUqoridagi satrning boshqacha yozilishi
    Misol. Bir hafta ichidagi kundalik temperatura berilgan bo’lsa, hafta uchun o’rtacha temperaturani hisoblash dasturini tuzish:


    //Haftalik o’rtacha tempraturani hisoblash dasturi
    #include
    #include
    using namespace std;
    int main()
    {
    const int n=7;
    int temp[n];
    int i, s, or_tem;
    s=0;
    cout<<"\n";
    cout<<" Kunlik tempraturani kiriting: \n";
    cout<<"\n";
    for( i=1; i<=n; i++)
    { cout<< " temp["< cin>>temp[i]; s=s+temp[i]; }
    or_tem=s/n;
    cout<<" ----------------------------------------";
    cout<<"\n";
    cout<<" Haftalik o’rtacha tempratura = "<
    getch();
    return 0;
    }
    Misollar kurib o’tamiz.
    1-misol. Massiv elementlaridan musbatlarining soni va summasini hisoblash dasturi.


    # include
    # include
    using namespace std;
    int main ()
    { int x[ ] = {1, 2, 56, 78, -7, -45, 34, 12, 9, -1};
    int s=0, n=0;
    for (int i = 0; i < 10; i++)
    { if (x[i] < 0) continue;
    s = s + x[i]; n++;}
    cout<<"\n";
    cout<<"musbat elementlar soni n="<
    cout<<"\n";
    cout<<"musbat elementlar yig`ndisi s="<
    getch ( );
    }

    Yoki huddi shu dasturni for va kiritish operatori cin orqali massivning 10 ta elementlarini kiritib hisoblash dasturini tuzish ham mumkin




    # include
    # include
    using namespace std;
    int main ()
    {
    int x[10], s=0, i, n=0;
    for (i=0; i<10; i++)
    { cout<<" x["<> x[i];}
    for (i=0; i<10; i++)
    { if (x[i]<0) continue;
    s =s+x[i]; n++ ;
    }
    cout<<"\n";
    cout<<"musbat elementlar soni n="<
    cout<<"\n";
    cout<<"musbat elementlar yig`ndisi s="<
    getch ( );
    }
    Download 18,54 Kb.
    1   2




    Download 18,54 Kb.