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 14
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
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.