The program below calculates and outputs the sum of the integers from 1 to 6.
int total = 0;
for (int i = 1; i <= 6; i++)
{
total = total + i;
}
Console.WriteLine(total);
The program needs to be changed so that it also calculates and outputs the sum of the squares of the integers from 1 to 6.
Select one option (A, B, C, or D) that shows the correct modified program.
int total = 0;
int sumOfSquares = 0;
for (int i = 1; i <= 6; i++)
{
total = total + i;
sumOfSquares = total * total;
}
Console.WriteLine(total);
Console.WriteLine(sumOfSquares);
int total = 0;
int sumOfSquares = 0;
for (int i = 1; i <= 6; i++)
{
total = total + i;
sumOfSquares = sumOfSquares + total * total;
}
Console.WriteLine(total);
Console.WriteLine(sumOfSquares);
int total = 0;
int sumOfSquares = 0;
for (int i = 1; i <= 6; i++)
{
total = total + i;
sumOfSquares = sumOfSquares + i * i;
}
Console.WriteLine(total);
Console.WriteLine(sumOfSquares);
int total = 0;
int sumOfSquares = 0;
for (int i = 1; i <= 6; i++)
{
total = total + i;
sumOfSquares = sumOfSquares + (total + i);
}
Console.WriteLine(total);
Console.WriteLine(sumOfSquares);
298 exam-style questions on AQA GCSE Computer Science Programming concepts. Each one has a worked solution and a mark scheme showing where the marks go.