ఒక్కో విలువను కలుపుతూ వెళ్లడం
సున్నా నుండి ప్రారంభించి, మీరు చేరుకున్న ప్రతి విలువను జోడించండి.
ఒక చిన్న ఉదాహరణ
మొదట2 + 4
ఫలితం6
using System;
int total = 0;
total += 2;
total += 4;
Console.WriteLine(total);
6
ప్రకటనలు
రోజువారీ ఉదాహరణలు
మూడు తరగతులు 5, 2, 4 పుస్తకాలను విరాళంగా ఇస్తాయి. గ్రంథాలయం తన అరలలో ఎన్ని పుస్తకాలు ఉంచగలదు?
మొదట5 + 2 + 4
ఫలితం11
using System;
int[] books = new int[] { 5, 2, 4 };
int total = 0;
int i = 0;
while (i < 3) {
total += books[i];
i += 1;
}
Console.WriteLine(total);
11
ఉదాహరణను రన్ చేయండి
dotnet new console --output Lesson
cp Program.cs Lesson/Program.cs
dotnet run --project Lesson