Академический Документы
Профессиональный Документы
Культура Документы
Solution:-
Private Sub Command1_Click()
Dim i As Integer
Dim x As Integer
n = InputBox("enter the value ")
For i = 2 To n / 2
If n Mod i = 0 Then
x=1
Exit For
http://informationtechnology.pk
2|Page Visual Basic 6.0 Punjab University papers
End If
Next i
If x = 0 Then
Print "prime"
Else
Print "composite"
End If
End Sub
Question no 2. Write a VB program that takes n numbers as input . it outputs the frequency of
positive and negative numbers . A sample input and out put as follows:-. 12.5
Input
N = 12
Output :-
Solution:-
Private Sub Command1_Click()
Dim n(11) As Integer
http://informationtechnology.pk
3|Page Visual Basic 6.0 Punjab University papers
Question NO 3. Write a VB program that reads n values in a list and print the product of the value
and position at which it resides in the list . product = L[1]*1 , product = L[2] * 2 and so on
Example:- position :- 1 2 3 4 5
Value 5 3 7 1 4
Output :- 5 6 21 4 20
Solution :-
Private Sub Command1_Click()
Dim n(1 To 5) As Integer
For i = 1 To 5
n(i) = InputBox("enter the values in to array")
Next i
Print " the output is as follwoing:"
For i = 1 To 5
Print n(i) * i
Next i
End Sub
http://informationtechnology.pk
4|Page Visual Basic 6.0 Punjab University papers
Question no . 2 write a VB program that takes N numbers as input . it print the maximum
number and its frequency (number of occurrence ) . 12.5
Sample no 1
N= 10
The 10 inputs are 7,20 , -1 , 65 , 36 , 90, 78 , 90 ,90 ,-2
Maximum is 90
Frequency is 3
Solution :-
7,8,90,34,2,9,12,1,10,32
Output :-
1,2,7,8,9,10,12,32,34,90
Solution:-
Private Sub Command1_Click()
Dim arr(4) As Integer, temp As Integer
Dim s As Integer
Dim e As Integer
s = InputBox("enter the value of s")
e = InputBox("enter the value of e")
For i = s To e
http://informationtechnology.pk
5|Page Visual Basic 6.0 Punjab University papers
Question no .2 write a VB program that should takes a number n as input . your program print first
10 multiples of n by using loop . 12.5
Solution :-
Private Sub Command1_Click()
Dim n As Integer
n = InputBox("enter the value of n")
For i = 1 To 10
Print "multiple" & n * i
Next i
End Sub
http://informationtechnology.pk
6|Page Visual Basic 6.0 Punjab University papers
Question no . 3 write a VB program that should takes 10 numbers as input and store them in an
array. It should print the number of even numbers among those numbers . you need to use if –else
and loop in your program . 12.5
Solution :-
Private Sub Command1_Click()
Dim n(9) As Integer
Dim sumeven As Integer
sumeven = 0
For i = 0 To 9
n(i) = InputBox("enter the value of n")
Next i
For i = 0 To 9
If n(i) Mod 2 = 0 Then
Print n(i)
sumeven = sumeven + 1
End If
Next i
MsgBox "total even number frequency=" & sumeven
End Sub
http://informationtechnology.pk
7|Page Visual Basic 6.0 Punjab University papers
evensum = evensum + 1
Else
oddsum = oddsum + 1
End If
Next i
Print "the frequency of even " & evensum
Print " the frequency of odd " & oddsum
End Sub
Question No 3. Write a program in VB that should takes 3 numbers from user as input . your
program find and print the square and cube of these three numbers on the screen . 12.5
Solution :-
Private Sub Command1_Click()
Dim a As Integer
Dim b As Integer
Dim c As Integer
a = InputBox("enter the value of a ")
b = InputBox("enter the value of b ")
c = InputBox("enter the value of c ")
Print "a =" & vbTab & a ^ 2 & vbTab & a ^ 3; vbNewLine & "b =" & vbTab & b ^ 2 & vbTab &
b ^ 3; vbNewLine & "c =" & vbTab & c ^ 2 & vbTab & c ^ 3; vbNewLine
End Sub
(B) write a VB program that inputs three distinct number and find and display middle one .
Solution :-
http://informationtechnology.pk
8|Page Visual Basic 6.0 Punjab University papers
http://informationtechnology.pk
9|Page Visual Basic 6.0 Punjab University papers
(b) . Write a VB program that should take a positive number n as input . your should display the
sum of all numbers between 1 to n numbers .
Solution : -
Private Sub Command1_Click()
Dim n As Integer
Dim sum As Integer
n = InputBox("enter the value")
For i = 1 To n
num = InputBox("enter the value")
Print num
sum = sum + num
Next i
Print "sum of all the num" & sum
End Sub
Question NO 3.(a) write a VB program that should take 10 number from user . your program
should find and display the maximum number . (6.0+6.5)
Solution:-
Private Sub Command1_Click()
Dim num As Integer
Dim max As Integer
Dim count As Integer
count = 0
max = num
num = InputBox("enter the value :")
Do While num > 0
count = count + 1
If num > max Then
max = num
End If
num = InputBox("enter the value for exit ")
Loop
Print "max num is = " & max
End Sub
OTHER SOLUTION
Private Sub Command1_Click()
Dim n(10) As Integer
Dim max As Integer
http://informationtechnology.pk
10 | P a g e Visual Basic 6.0 Punjab University papers
For i = 1 To 10
n(i) = InputBox("enter the 10 value")
Next i
max = n(1)
For i = 1 To 10
Print n(i)
If max < n(i) Then
max = n(i)
End If
Next i
Print "max =" & max
End Sub
(b) write a program that should takes two numbers (that is , first and last ) from the user and display
all the numbers and their square in the form of an order pair between first and last numbers
Solution :-
http://informationtechnology.pk
11 | P a g e Visual Basic 6.0 Punjab University papers
3. visual programming
Question No 1(b) running on a particular treadmill burn 3.9 calories per minutes . write a program
that uses a loop to display the number of calories burned after 10, 15 ,20 , 25 and 30 minutes
Solution:-
Private Sub Command1_Click()
Dim calories As Single
Dim total_cal As Double
total_cal = 0
calories = InputBox("enter the calories")
For i = 10 To 30 Step 5
Print calories * i
total_cal = total_cal + calories * i
Next i
Print "total calories" & total_cal
End Sub
With constant
Private Sub Command1_Click()
Const calories As Single = 3.9
Dim total_cal As Double
total_cal = 0
For i = 10 To 30 Step 5
Print calories * i
total_cal = total_cal + calories * i
Next i
Print "total calories" & total_cal
End Sub
Question NO 2(a) A country club , which currently charge RS. 2500 per year for membership has ,
announced it will increase its membership fee by 4% each year for next 6 years . write a program
uses loop to display the projected for next six years. (6.0+6.5)
Solution:-
Private Sub Command1_Click()
Dim membership As Integer
http://informationtechnology.pk
12 | P a g e Visual Basic 6.0 Punjab University papers
Question No 2(b) write a VB program that should takes 10 positive numbers as input . your
program should display the sum of all the numbers from 1 to n numbers .
Solution:-
Private Sub Command1_Click()
Dim n As Integer
Dim sum As Integer
sum = 0
For i = 1 To 10
n = InputBox("enter the value")
Print n
sum = sum + n
Next i
Print "sum of numbers" & sum
End Sub
Question NO 3(a) write a VB program that should takes 10 minutes from user and save in an array
. your program should sort and display these numbers in ascending order. (6.0+6.5)
Private Sub Command1_Click()
Dim arr(4) As Integer, temp As Integer
Dim s As Integer
Dim e As Integer
s = InputBox("enter the value of s")
e = InputBox("enter the value of e")
For i = s To e
arr(i) = InputBox("enter the time in min")
Next i
For i = s To e
Print arr(i)
Next i
http://informationtechnology.pk
13 | P a g e Visual Basic 6.0 Punjab University papers
For i = s To e
For j = s To e - 1
If arr(j) > arr(j + 1) Then
temp = arr(j)
arr(j) = arr(j + 1)
arr(j + 1) = temp
End If
Next j
Next i
Print "sorted array "
For i = s To e
Print arr(i)
Next i
End Sub
Question N0 .3(b) write a program that asks the user to enter the amount that he or she budgeted
for a month . A loop should then user to enter each of his or her expenses for the month and keep a
running total . when the loop finishes , the program should displays the amount that user is over
or under the budgets .
Solution:-
Private Sub Command1_Click()
Dim budget As Integer
Dim val As Integer
Dim exp As Integer
exp = 0
budget = InputBox("enter the budget")
Do
val = InputBox("enter the expenses or enter the 0 to end ")
exp = exp + val
Loop While (val <> -1)
If budget > exp Then
Print " expenses under the budget"
Else
Print " expenses over the budget"
End If
End Sub
http://informationtechnology.pk