Answer to Question #194792 in Visual Basic for abcdefna

Question #194792

Write a statement or a set of statements to accomplish each of the following:

>Sum the odd integers between 1 and 99 using a For/Next structure. Assume that variables sum and count have been declared explicitly as Integer.

>Print the number from 20 to 1 on the form using a Do Until loop and Integer counter variable x. Assume that the variable x is initialized to 20.

>Print the Integers from 1 to 20 using a Do/Loop While structure and the counter variable x. Assume that x has been declared as an integer but not initialized.



1
Expert's answer
2021-05-18T02:58:22-0400
Module Module1


    Sub Main()
        'Sum the odd integers between 1 and 99 using a For/Next structure. Assume that variables sum and count have been declared explicitly as Integer.
        Dim sum As Integer = 0
        Dim count As Integer = 0
        For i As Integer = 1 To 99
            If i Mod 2 <> 0 Then
                count += 1
                sum += i
            End If
        Next
        Console.WriteLine("Sum = {0}", sum)
        Console.WriteLine("Count = {0}", count)
        Console.WriteLine()
        Console.WriteLine("The number from 20 to 1 on the form using a Do Until loop:")
        'Print the number from 20 to 1 on the form using a Do Until loop and Integer counter variable x. Assume that the variable x is initialized to 20.
        Dim x As Integer = 20
        Do
            Console.WriteLine("{0}", x)
            x -= 1
        Loop Until x < 1
        'Print the Integers from 1 to 20 using a Do/Loop While structure and the counter variable x. Assume that x has been declared as an integer but not initialized.
        Console.WriteLine()
        Console.WriteLine("The number from 1 to 20 on the form using a Do/Loop While:")
        x = 1
        Do
            Console.WriteLine("{0}", x)
            x += 1
        Loop While x <= 20
        Console.ReadLine()
    End Sub


End Module

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS