You are on page 1of 5

Programs

1.WAP to make arithmetic operations


Imports System

Module Program
Sub Main(args As String())
Console.WriteLine("Enter first number")
Dim a As Integer = Integer.Parse(Console.ReadLine())
Console.WriteLine("Enter Second number")
Dim b As Integer = Integer.Parse(Console.ReadLine())
Dim add As Integer = a + b
Console.WriteLine("Addtion of two numbers is :" & add)
Dim su As Integer = a - b
Console.WriteLine("substraction of two numbers is :" & su)
Dim mul As Integer = a * b
Console.WriteLine("product of two numbers is :" & mul)
Dim div As Integer = a / b
Console.WriteLine("div of two numbers is :" & div)
Console.ReadKey()

End Sub
End Module

Q.) Write a program to calculate the area of a rectangle. Prompt the


user to enter the length and width of the rectangle, and display the
calculated area.
Imports System

Module Program
Sub Main(args As String())
Console.WriteLine("Enter first length")
Dim l As Integer = Integer.Parse(Console.ReadLine())
Console.WriteLine("Enter first Width")
Dim w As Integer = Integer.Parse(Console.ReadLine())

Dim area As Integer = l * w


Console.WriteLine("Area Of Rectangle =" & area)

End Sub
End Module

Output

2. Write a program that converts temperature from Celsius to Fahrenheit. Prompt the user
to enter a temperature in Celsius, and display the equivalent temperature in Fahrenheit.
mports System
Imports System.Runtime.InteropServices

Module Program
Sub Main(args As String())
Console.WriteLine("Enter Celsius ")
Dim c As Double = Double.Parse(Console.ReadLine())

Dim f As Double = ((c * 9) / 5) + 32


Console.WriteLine("Temperature in Fahrenheit Is :" & f)

End Sub
End Module

Output:

3. Write a program that calculates the average of three numbers. Prompt the user to enter
three numbers, and display the calculated average.
Imports System
Imports System.Runtime.InteropServices

Module Program
Sub Main(args As String())
Console.WriteLine("Enter First Number: ")
Dim A As Integer = Integer.Parse(Console.ReadLine())
Console.WriteLine("Enter Second Number: ")
Dim b As Integer = Integer.Parse(Console.ReadLine())
Console.WriteLine("Enter third Number: ")
Dim c As Integer = Integer.Parse(Console.ReadLine())

Dim avg As Double = (A + b + c) / 3


Console.WriteLine("The three number average is: " & avg)

End Sub
End Module
Output:

4. Write a program that determines whether a given number is even or odd. Prompt the
user to enter a number, and display whether it is even or odd.
Imports System
Imports System.Runtime.InteropServices

Module Program
Sub Main(args As String())
Console.WriteLine("Enter any Number: ")
Dim a As Integer = Integer.Parse(Console.ReadLine())

If (a Mod 2 = 0) Then
Console.WriteLine("The Given Number is Even: " & a)
Else
Console.WriteLine("The Given Number is Odd: " & a)
End If
End Sub
End Module

Output:

5. Write a program that calculates the factorial of a given number. Prompt the user to
enter a number, and display the factorial.
Imports System
Imports System.Runtime.InteropServices

Module Program
Sub Main(args As String())
Console.WriteLine("Enter any Number: ")
Dim n As Integer = Integer.Parse(Console.ReadLine())

Dim fact As Integer = 1


Dim i As Integer = 1

For i = 1 To n Step 1
fact = fact * i

Next

Console.WriteLine("The given number Factorial is : " & fact)

End Sub
End Module
Output:

6. Write a program that checks if a given year is a leap year or not. Prompt the user to
enter a year, and display whether it is a leap year or not.
Imports System
Imports System.Reflection.Emit
Imports System.Runtime.InteropServices

Module Program
Sub Main(args As String())
Console.WriteLine("Enter any Year : ")
Dim year As Integer = Integer.Parse(Console.ReadLine())

Dim a As Integer
Dim b As Integer
Dim c As Integer

a = year Mod 4
b = year Mod 100
c = year Mod 400
If ((a = 0 And Not (b = 0)) Or c = 0) Then
Console.WriteLine("This is Leap Year")
Else
Console.WriteLine("This is Not Leap Year")
End If

End Sub
End Module
Output:

7. Write a program that calculates the sum of the digits of a given number. Prompt the
user to enter a number, and display the sum of its digits.
Imports System
Imports System.Globalization
Imports System.Reflection.Emit
Imports System.Runtime.InteropServices

Module Program
Sub Main(args As String())

Console.WriteLine("Enter any Number: ")


Dim digit As Integer = Integer.Parse(Console.ReadLine())
Dim sum, remainder As Integer

While (digit > 0)


remainder = digit Mod 10
sum = sum + remainder
digit = digit \ 10
End While

Console.WriteLine("The Number of Given digit is:" & sum)


End Sub
End Module
8. Write a program that checks if a given string is a palindrome. Prompt the user to enter a
string, and display whether it is a palindrome or not.

You might also like