0% found this document useful (0 votes)
4 views8 pages

Programming Qns

The document contains a series of Visual Basic programs that perform various tasks such as calculating the square of a number, finding the maximum of three numbers, sorting three numbers, checking if a number is even, swapping two numbers, summing the digits of a five-digit number, reversing a five-digit number, calculating areas and perimeters of shapes, computing gross salary, converting distances, and calculating average marks. Each program prompts the user for input and displays the result. The examples demonstrate fundamental programming concepts and operations in Visual Basic.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

Programming Qns

The document contains a series of Visual Basic programs that perform various tasks such as calculating the square of a number, finding the maximum of three numbers, sorting three numbers, checking if a number is even, swapping two numbers, summing the digits of a five-digit number, reversing a five-digit number, calculating areas and perimeters of shapes, computing gross salary, converting distances, and calculating average marks. Each program prompts the user for input and displays the result. The examples demonstrate fundamental programming concepts and operations in Visual Basic.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Qn1

sub Main()
Dim number As Double
Dim square As Double

[Link]("Enter a number: ")


number = [Link]()

square = number * number

[Link]("The square of the number is: " & square)


[Link]()
End Sub
QS2

Sub Main()

Dim num1, num2, num3, maxNum As Integer

[Link]("Enter the first number: ")

num1 = [Link]()

[Link]("Enter the second number: ")

num2 = [Link]()

[Link]("Enter the third number: ")

num3 = [Link]()

maxNum = num1

If num2 > maxNum Then

maxNum = num2

End If

If num3 > maxNum Then

maxNum = num3

End If
[Link]("The maximum number is: " & maxNum)

[Link]()

End Sub

QN03

Sub Main()

Dim num1, num2, num3, temp As Integer

[Link]("Enter the first number: ")

num1 = [Link]()

[Link]("Enter the second number: ")

num2 = [Link]()

[Link]("Enter the third number: ")

num3 = [Link]()

' Sort the numbers

If num1 > num2 Then

temp = num1

num1 = num2

num2 = temp

End If

If num2 > num3 Then

temp = num2

num2 = num3

num3 = temp

End If
If num1 > num2 Then

temp = num1

num1 = num2

num2 = temp

End If

[Link]("The numbers in ascending order are: " & num1 & ", " & num2 & ", " & num3)

[Link]()

End Sub

QS 4
Module Module1

Sub Main()
Dim num As Integer

[Link]("Enter a number: ")


num = [Link]()

If num Mod 2 = 0 Then


[Link]("True")
Else
[Link]("False")
End If

[Link]()

End Sub

End Module

Qs5

Sub Main()

Dim Value1, Value2, temp As Integer

[Link]("Enter the first number: ")


Value1 = [Link]()

[Link]("Enter the second number: ")

Value2 = [Link]()

' Swapping the values

temp = Value1

Value1 = Value2

Value2 = temp

[Link]("After swapping, the content of Value1 is: " & Value1)

[Link]("After swapping, the content of Value2 is: " & Value2)

[Link]()

End Sub

Qn 6

Sub Main()

Dim num, sum, digit As Integer

[Link]("Enter a five-digit number: ")

num = [Link]()

sum = 0

While num <> 0

digit = num Mod 10

sum = sum + digit

num = num \ 10

End While
[Link]("The sum of the digits is: " & sum)

[Link]()

End Sub

QN7

Sub Main()

Dim num, reversedNum, digit As Integer

[Link]("Enter a five-digit number: ")

num = [Link]()

reversedNum = 0

While num <> 0

digit = num Mod 10

reversedNum = reversedNum * 10 + digit

num = num \ 10

End While

[Link]("The reversed number is: " & reversedNum)

[Link]()

End Sub

QN8

Sub Main()
Dim length, breadth, radius As Double

Dim areaRectangle, perimeterRectangle, areaCircle, circumferenceCircle As Double

[Link]("Enter the length of the rectangle: ")

length = [Link]()

[Link]("Enter the breadth of the rectangle: ")

breadth = [Link]()

[Link]("Enter the radius of the circle: ")

radius = [Link]()

' Calculate the area and perimeter of the rectangle

areaRectangle = length * breadth

perimeterRectangle = 2 * (length + breadth)

' Calculate the area and circumference of the circle

areaCircle = 3.14 * radius * radius

circumferenceCircle = 2 * 3.14 * radius

[Link]("The area of the rectangle is: " & areaRectangle)

[Link]("The perimeter of the rectangle is: " & perimeterRectangle)

[Link]("The area of the circle is: " & areaCircle)

[Link]("The circumference of the circle is: " & circumferenceCircle)

[Link]()

End Sub

QN9.

Sub Main()
Dim basicSalary As Double

Dim dearnessAllowance As Double

Dim houseRentAllowance As Double

Dim grossSalary As Double

[Link]("Enter the basic salary: ")

basicSalary = [Link]([Link]())

dearnessAllowance = 0.4 * basicSalary

houseRentAllowance = 0.2 * basicSalary

grossSalary = basicSalary + dearnessAllowance + houseRentAllowance

[Link]("The gross salary is: " & grossSalary)

End Sub

QN10

Sub Main()
Dim number As Integer

[Link]("Enter any number: ")


number = [Link]()

If number Mod 2 = 0 Then


[Link]("You have entered an even number.")
Else
[Link]("The number entered is not an even number.")
End If
[Link]()
End Sub

QN11

Sub Main()
Dim distanceKm As Double
Dim distanceMeters As Double
Dim distanceFeet As Double
Dim distanceInches As Double
Dim distanceCm As Double
[Link]("Enter the distance between two cities in km: ")
distanceKm = [Link]()

' Convert kilometers to other units


distanceMeters = distanceKm * 1000
distanceCm = distanceMeters * 100
distanceInches = distanceCm / 2.54
distanceFeet = distanceInches / 12

' Print the results


[Link]("The distance in meters is: " & distanceMeters)
[Link]("The distance in feet is: " & distanceFeet)
[Link]("The distance in inches is: " & distanceInches)
[Link]("The distance in centimeters is: " & distanceCm)
[Link]()
End Sub

Qn12

sub Main()
Dim marks1 As Double
Dim marks2 As Double
Dim marks3 As Double
Dim marks4 As Double
Dim marks5 As Double
Dim averageMarks As Double

[Link]("Enter the marks for subject 1: ")


marks1 = [Link]()

[Link]("Enter the marks for subject 2: ")


marks2 = [Link]()

[Link]("Enter the marks for subject 3: ")


marks3 = [Link]()

[Link]("Enter the marks for subject 4: ")


marks4 = [Link]()

[Link]("Enter the marks for subject 5: ")


marks5 = [Link]()

' Calculate the average marks


averageMarks = (marks1 + marks2 + marks3 + marks4 + marks5) / 5

' Print the results


[Link]("The average marks obtained by the student is: " &
averageMarks)
[Link]()
End Sub

You might also like