The following code is intended to calculate the sum of the first five positive odd
integers.
int sum = 0, k;
for (k = 1; k <= 10; k += 2) {
sum += k;
}
What is wrong with this code segment?
a. The segment calculates the sum of the first four positive odd integers.
b. The segment calculates the sum of the first six positive odd integers.
c.The segment calculates the sum of the first seven positive odd integers.
d. The variable sum is incorrectly initialized. The segment would work correctly if sum
was initialized to 1.
e.The segment works as intended.
It's always a good idea to initialize variables. the term initialize refers to giving a variable a starting value... such as; ``` int y = 0, k = 0, z = 0, fish = 0, dog = 0; String str = "", str2 = ""; ```
Not doing so can lead to compilation errors - though it depends on the language.
a
Join our real-time social learning platform and learn together with your friends!