C# QUESTION 1 How many times is the loop body of the while statement executed? i
ID: 3703304 • Letter: C
Question
C#
QUESTION 1
How many times is the loop body of the while statement executed?
int i = 0, g = 0, s = 0, t = 0, z = 0;
string sValue;
while (i < 5)
{
inValue = ReadLine( );
t = Convert.ToInt32(inValue);
s = s + t;
if (t > ?1)
g = g + 1;
else
z = z + 1;
i = i + 1;
}
once
never
four times
five times
until a number 5 or larger is entered
1.00000 points
QUESTION 2
What would be the output produced from the following statements?
int i = 0;
while (i < 0)
{
Write("{0} ", i);
i++;
}
Write("{0} ", i);
0
an infinite loop
an error
0 0
none of the above
1.00000 points
QUESTION 3
Which of the following for statements would be executed the same number of times as the following while statement?
int num = 10;
while(num > 0)
{
WriteLine(num);
num--;
}
for (num = 1; num < 10; num++)
for (num = 0; num < 10; num++)
for (num = 100; num == 10; num += 10)
for (num = 10; num < 0; num--);
none of the above
1.00000 points
QUESTION 4
The ____________ statement is a pretest form of loop which is considered a specialized form of the while statement and is usually associated with counter-controlled types of loops;
1.00000 points
QUESTION 5
With the while loop, the body of the loop is ____.
always performed at least one time
performed as long as the conditional expression evaluates to true
must produce a boolean result
must be enclosed in curly braces
none of the above
1.00000 points
QUESTION 6
The first value printed with the program segment below is ____.
int counter = 0;
while (counter < 100)
{
WriteLine(counter);
counter++;
}
0
1
99
100
none of the above
1.00000 points
QUESTION 7
Reviewing the code snippet below, the value stored in variable z at the end of the execution of the loop could best be described as:
int i = 0, g = 0, s = 0, t = 0, z = 0;
string sValue;
while (i < 5)
{
inValue = ReadLine( );
t = Convert.ToInt32(inValue);
s = s + t;
if (t > ?1)
g = g + 1;
else
z = z + 1;
i = i + 1;
}
the number of positive items entered
the sum of all positive items entered
the number of negative items entered
the sum of all negative items entered
the sentinel value
1.00000 points
QUESTION 8
If you intend to place a block of statements within a loop body, you must use ___________ around the block.
parentheses
square brackets
quotation marks
curly braces
none of the above
1.00000 points
QUESTION 9
Given the following statement, __________ would be the output produced
for (int cnt = 0; cnt < 3; cnt++)
Write(cnt);
1.00000 points
QUESTION 10
Loops are needed in programming languages:
to facilitate sequential processing of data
to enable a variable to be analyzed for additional processing
to allow statements to be repeated
to process files stored on hard drives
all of the above
1.00000 points
QUESTION 11
A(n) ____________loop is a loop that has no provisions for termination.
1.00000 points
QUESTION 12
The third programming construct repetition is also called ____________.
1.00000 points
QUESTION 13
______________ refers to the region in the program in which you can use the variable.
1.00000 points
QUESTION 14
Reviewing the code snippet below, the loop can best be categorized as a:
int i = 0, g = 0, s = 0, t = 0, z = 0;
string sValue;
while (i < 5)
{
inValue = ReadLine( );
t = Convert.ToInt32(inValue);
s = s + t;
if (t > ?1)
g = g + 1;
else
z = z + 1;
i = i + 1;
}
counter-controlled loop
sentinel-controlled loop
state-controlled loop
flag-controlled loop
none of the above
1.00000 points
QUESTION 15
If aValue, i, and n are type int variables, what does the following program fragment do?
aValue = 0; n = 10;
for (i = n; i > 0; i--)
if (i % 2 == 0)
aValue = aValue + i;
computes the sum of the integers from 1 through n
computes the sum of the integers from 1 through n ?1
computes the sum of the even integers from 1 through n
computes the sum of the odd integers from 1 through n
none of the above
once
never
four times
five times
until a number 5 or larger is entered
Explanation / Answer
According to chegg guidelines i have to solve first four bits only but i solve 5 bits please do multiple posts to get all answers.
1.
i = 0
while (i < 5) // It runs for i value 0 to 4 total 5 times
Here everytime i value incremented by 1
Option 4 correct.
2.
int i = 0; // initially value is 0
while (i < 0) // Loop runs untill negative values
i++; // i value is always incremented by so i value is 1,2,3....n so i value never negative so it is an infinite loop
Option 2 correct.
3.
int num = 10; // initially num is 10
while(num > 0) // loop runs 10 to 1
{
num--; // num is decremented by 1
}
Equivalent for loop
for (num = 10; num > 0; num--);
Option 5 correct.
4.
for statement is a pretest form of loop which is considered a specialized form of the while statement and is usually associated with counter-controlled types of loops;
Example :
for (num = 10; num > 0; num--);
Here loop runs from 10 to 1
It always check before go to the body of for loop
5.
With the while loop, the body of the loop is performed as long as the conditional expression evaluates to true
int num = 10;
while(num > 0) // Here condition is num > 0, it runs until num is greater than 0
{
num--; // num is decremented by 1
}
for (num = 10; num > 0; num--);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.