Photo AI

A programmer has written the C# program in Figure 5 to add up the numbers between one and five - AQA - GCSE Computer Science - Question 14 - 2021 - Paper 1

Question icon

Question 14

A-programmer-has-written-the-C#-program-in-Figure-5-to-add-up-the-numbers-between-one-and-five-AQA-GCSE Computer Science-Question 14-2021-Paper 1.png

A programmer has written the C# program in Figure 5 to add up the numbers between one and five. int total = 0; for (int number = 1; number < 6; number++) { tota... show full transcript

Worked Solution & Example Answer:A programmer has written the C# program in Figure 5 to add up the numbers between one and five - AQA - GCSE Computer Science - Question 14 - 2021 - Paper 1

Step 1

Identify the correct program modification

96%

114 rated

Answer

The correct modification is given in option B:

int total = 0;
int product = 1;
for (int number = 1; number < 6; number++)
{
    total = total + number;
    product = product * number;
}
Console.WriteLine(total);
Console.WriteLine(product);

This program calculates the sum of numbers from 1 to 5 with total and their product with product. This meets the requirement to add and multiply the numbers between one and five.

Join the GCSE students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;