Knowee
Questions
Features
Study Tools

Write a vb.net program that uses a sub procedure to calculate and sum of all even numbers between 1 and n where n is supplied by the user

Question

Write a vb.net program that uses a sub procedure to calculate and sum of all even numbers between 1 and n where n is supplied by the user

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple VB.NET program that uses a sub procedure to calculate the sum of all even numbers between 1 and n.

Imports System

Module Program
    Sub Main(args As String())
        Console.Write("Enter a number: ")
        Dim n As Integer = Integer.Parse(Console.ReadLine())
        Dim sum As Integer = SumOfEvenNumbers(n)
        Console.WriteLine("The sum of all even numbers from 1 to " & n & " is " & sum)
    End Sub

    Function SumOfEvenNumbers(n As Integer) As Integer
        Dim sum As Integer = 0
        For i As Integer = 1 To n
            If i Mod 2 = 0 Then
                sum += i
            End If
        Next
        Return sum
    End Function
End Module

This program works as follows:

  1. It prompts the user to enter a number.
  2. It reads the user's input and converts it to an integer.
  3. It calls the SumOfEvenNumbers function, passing the user's number as an argument.
  4. The SumOfEvenNumbers function calculates the sum of all even numbers from 1 to the user's number.
  5. It prints the result to the console.

This problem has been solved

Similar Questions

Program to ask a user for supplying n different integers and countthe total number of even and odd values among them

Write a program to accept an integer N and print the sum of first N odd numbersInput Format:An integer range is given inputOutput Format:Print only calculated sum.Constraints:1 <= N <= 10^16 Sample Input 1:2Sample Output 1:4Sample Input 2:10Sample Output 2:100

Problem Statement:Find the sum of even numbers in the given range.Input Format:Accept two integer as inputOutput Format:Print the output as sum of even number available in the given rangeConstraints:1 <= INPUT <= 10^15Sample Input 1:10 20Sample Output 1:90Sample Input 2:30 33Sample Output 2:62

Write a C++ program to find the sum of even and odd n natural numbers

Sum of EvenSend FeedbackProblem Statement:Write a program that takes a tuple as input and prints the sum of all the even numbers in the tuple.Input:A tuple containing integer elements.Output:The sum of all the even numbers in the tuple.Sample Input:(2, 3, 4, 6, 7)Sample Output:12

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.