Array ဆိုတာ type တူတဲ့ value များစွာကို name တစ်ခုအောက်မှာ သိမ်းတဲ့ collection ပါ။ Student score ၅ ခု၊ product price list, daily temperature list စတာတွေကို array နဲ့သိမ်းလို့ကောင်းပါတယ်။
c
#include <stdio.h>
int main() {
int scores[] = {80, 75, 90, 60};
int total = 0;
for (int i = 0; i < 4; i++) {
total += scores[i];
}
printf("Total: %d
", total);
printf("Average: %.2f", total / 4.0);
return 0;
}scores[0] က ပထမ item ဖြစ်ပါတယ်။ Loop က index 0 မှ 3 အထိပတ်ပြီး score တွေကို total ထဲပေါင်းပါတယ်။
You should see
Total: 305 Average: 76.25Info
Array index က 0 ကစပါတယ်။ Item 4 ခုရှိရင် last index က 3 ပါ။