Skip to content

Course home

Programming concepts

Programming concepts

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
Question 68

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.

A
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);
B
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);
C
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);
D
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);
Markscheme

Programming concepts Questions

  1. GCSE
  2. /Computer Science
  3. /Programming concepts

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.

Question bank