DEV Community

BUTTSAN
BUTTSAN

Posted on

1 1 1 1 1

cpp codlash tilidagi Array

Array bu - bir xil turdagi ma'lumotlarni saqlash uchun ishlatiladigan ma'lumot tuzilmasidir. U tartiblangan elementlar to'plamidan iborat bo'lib, indekslash yordamida har bir elementga murojaat qilish mumkin. Indekslash 0 dan boshlanadi.
misol:

#include <cmath>
#include <ctime>
#include <climits>
#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
    int score[4] = {3, 5, 10, 7};

    score[3] = 2;

    cout << score[3] << endl;

    return 0;
}
Enter fullscreen mode Exit fullscreen mode

Array men tushi shim boyicha python dagi royhatga ohshaydi
bu gapim bilan nima dimoqchiman array mavzu men uchun global mavzu ems bu

if ga ohshagan mavzu.
bu codda men score degan array yaratdim va unga qiymat berdim
krlgin esa men uni 3 indexda turgan ballni 2 ga tengladim.
va ohirida 3 indexdagi soni consolega chiqardim.
va yanna bir malumot array da счёт 0 dan boshlanadi bu degani 3 indexda 10 emas 7 turibti va yana sizda bir savol tugilishi mumkin arrayda ozimiz qiymat kirititshiimiz mumkinmi?
ha albatta!!!
misol:

{
int score[4];

for(int i = 0; i < 4; i++)
{
    cin >> score[i];
}
for(int i = 0; i < 4; i++)
{
    cout <<  score[i];
}
    return 0;
}

Enter fullscreen mode Exit fullscreen mode

bu coda men for bilan yozdim chunki agar cin da bir ma bin yozganimizda vaqtimiz kop ketib qoladi.
va albatda if bilan ham ishlasa boladi:

#include <iostream>
using namespace std;

int main() {
    int numbers[5] = {10, 15, 20, 25, 30};

    cout << "Juft sonlar:" << endl;

    for (int i = 0; i < 5; i++) {
        if (numbers[i] % 2 == 0) {
            cout << numbers[i] << " ";
        }
    }

    return 0;
}

Enter fullscreen mode Exit fullscreen mode

va shu bilan boldi agar men biror nimani qoldirgan bolsam commentga yozi ketting meni postimni oqiganiz uchun rahmat😊

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay