class Program
{
static void Main(string[] args)
{
int[] a = new int[5];
int Sum, Avg;
Console.WriteLine("Enter
5 Marks : ");
for (int i = 0; i
< a.Length; i++)
a[i] = int.Parse(Console.ReadLine());
Sum = 0;
for (int i = 0; i
< a.Length - 1; i++)
{
Sum += a[i];
}
Avg = Sum / a.Length;
Console.WriteLine("Total
Mark : " + Sum);
Console.WriteLine("Average
Mark : " + Avg);
Console.ReadLine();
}
}
Output :
why here taken i<a.length-1...?
ReplyDeletecondition mentioned there was wrong
DeleteUse this
i<=a.Length-1
or
i<a.Length
there is no necessity of two for loops
ReplyDeleteYes kartheekayan correct.
ReplyDeleteBut for understanding purpose I performed with separate loop