Quiz #5
1. Write a complete C# program that declares an integer array, named b, of size 12 elements. In the i-th element of the array store the square of i. Sum the values in the array and print each element of the array on a separate line. Then on the next line print the sum.
using System;
namespace Quiz5
{
public class Quiz5
{
static void Main(string[] args)
{
int sum = 0;
int[] b = new int[12];
for (int i = 0; i < b.Length; i++)
{
b[i] = i * i;
sum = sum + b[i];
System.WriteLine("b[{0}] = {1}", i, b[i]);
}
Console.WriteLine("b[0] + ... + b[{0}] = {1}", b.Length-1, sum);
}
}
}