Which code snippet produces the sum of the first n even numbers?
A) int sum = 0;
For (int i = 1; i <= n; i++)
{
If (i % 2 == 0)
{
Sum = sum + i;
}
}
B) int sum = 0;
For (int i = 1; i <= n; i++)
{
Sum = sum + i * 2;
}
C) int sum = 0;
For (int i = 0; i < n; i++)
{
If (i % 2 == 0)
{
Sum = sum + i;
}
}
D) int sum;
For (int i = 1; i <= n; i++)
{
Sum = sum + i * 2;
Correct Answer:
Verified
Q95: Which statement about storyboards is true?
A)A storyboard
Q104: Which of the following conditions can be
Q105: What is the first and last value
Q106: How many times does the following loop
Q107: For which input values will the following
Q108: Which of the following loops will print
Q111: Suppose you must design a program to
Q112: Which of the following activities can be
Q113: A loop inside another loop is called:
A)
Q114: What will be the range of the
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents