Write a statement or a set of statements to accomplish each of the following: a)
ID: 3545800 • Letter: W
Question
Write a statement or a set of statements to accomplish each of the following:
a) Sum the off integers between 1 and 99 using a while statement. Assume that variables sum and count have been declared as integers.
b) Sum the squares of the even integers between 1 and 15 using a Do While...Loop repitition statement. Assume that the integer variables sum and count have been declared and initialized to 0 and 2.
c) Print the numbers from 20 to 1 to the command propmt using a Do until...Loop and integer counter variable counterIndex. Assume that the variable counterIndex is initialized to 20.
d) Repeat exercise c) using a Do While...Loop statement
AND
Identify and correct the error(s) in each of the following (you may need to add code): Assume that value has been initialized to 50. The values from 0 to SO should be summed. This segment should read an unspecified number of positive values from the user and sum them. Assume that number and total are declared as Integers. The following code should print the squares of 1 to 10. This segment should print the values from 888 to 1000. Assume value is declared as an Integer.
Explanation / Answer
a>
statement will be :
sum=0
count=1
While count<=99
sum += count
count += 1;
End While
b>
Do While count <= 15
sum += count*count
count = count+2
Loop
c>
Do
Console.Write(counterIndex.ToString & " ")
counterIndex -= 1
Loop Until counterIndex=0
d>
Do While counterIndex>0
Console.Write(countIndex.ToString & " ")
counterIndex -= 1
Loop
e> snapshot
a> while value >=0
sum += value ;
value -= 1
End While
b>
Dim number As Interger =1
Do
Console.Write("Enter a positive value ; -1 to termenate :")
number = Console.ReadLine();
total += number
Loop Until number = -1
total -= 1
c>
Dim number As Interger =1
Do While number < 10
Console.WriteLine(number^2)
number -= 1
Loop
d>
value = 888
while value <= 1000
Console.Write(value.ToString & " ")
value -= 1
End While
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.