Вы находитесь на странице: 1из 24

ASSIGNMENT-3

Q1> Write a program to print first 50 natural numbers? Sol> Private sub command1_click() Dim i as integer For i = 1 to 50 Print i Next i End sub

Q2> Write a program to print all even numbers between( 1-50)? Ans> Private sub command1_click() Dim i as integer For i = 0 to 50 Step 2 Print i Next i End sub

Q3> Write a program to print first 10 natural numbers in reverse order? Sol> Private sub command1_click() Dim i as integer For i = 10 to 1 step -1 Print i Next i End sub

Q4> Write a program to enter any number from the user. Print its first 10 multiplies? Sol> Private sub command1_click() Dim i as integer Dim m as integer i = text1.text for m = 1 to 10 print m*i next m end sub

Q>5 Write a program to print the sum of first 10 natural numbers? Sol> Private sub command1_click() Dim i as integer Dim sum as integer Sum = 0 For i = 1 to 10 Sum = i + sum Next i Print sum End sub

Q6> Write a program to print the product of first 10 natural numbers? Sol> Private sub command1_click() Dim i as integer Dim product as long Product = 1 For i = 1 to 10 Product= product* i Next i Print product End sub

Q7> Write a program to enter any number from the user and display its factorial in another textbox? SOL> Private sub command1_click() Dim fact as integer Dim i as integer Dim num as integer Num= text1.text For i = 1 to num Fact= i* fact Next i Text2.text= fact End sub

Q8> Write a program to find out whether the number is odd or even? Sol> Private sub commad1_click() Dim i as integer i = text1.text if i mod 2 = 0 then msgbox(even number) else msgbox(odd number) end if end sub

Q9> print the sum of the following series if the value of x and n are input from user? Sol> Private sub command1_click() Dim x As Integer Dim n As Integer Dim sum As Double x = Val(Text1.Text) n = Val(Text2.Text) sum = 0 For i = 0 To n sum = sum + (1 / (x ^ i)) Next i Text3.Text = sum End sub

Q10> Write a program to show the usage of static variables? Sol> Private sub command1_click() Call example End sub Sub example() Static istatic as integer istatic = istatic+1 print istatic end sub

Assignment-4

Q1> Let the user input number of terms. Write a function to print fabonacii series? Sol> private sub command1_click() call fabonacci_series() end sub() function fabonacci_series() dim num as integer dim a as integer dim b as integer dim c as integer dim i as integer num = text1.text a=0 b=1 print a print b for i = 1 to num-2 c=a+b print c a=b b=c next i end function

Q2> Write a program to find out the total salary including HRA, city allwance, Vehicle allowance? Sol> Private sub command1_click() Text3.text= (59/100)*text2.text Text4.text= 800 If check1.value= 1 then Text5.text=0 Else Text5.text=800 End if Text6.text= val(text3.text) + val( text4.text) + val(text5.text) End sub

Q3> Write a function to find out whether the number input by the user is prime number or not? Sol> Private Sub Command1_Click() Dim i, x As Integer Dim flag As Boolean flag = False x = Val(Text1.Text) For i = 2 To x - 1 If (x Mod i = 0) Then flag = True End If Next If flag = True Then Print "not prime" Else Print "prime no." End If

End Sub

Q4> Write a program to enter different number from the user until the user enters zero? Sol> Private sub command1_click() Dim num as integer Dim sum as integer Sum=0 Do Num = inputbox(enter number, number entry form) Sum= sum +num Print sum Loop while num<>0 End sub

Q5> write a program to enter a name and age by the user. If the age lies between(18 to 40 yrs), display in the message boxYou are elgible for the interview, otherwise display you are not eligible for interview. Sol> Private Sub Command1_Click() Dim I As Integer I = Text2.Text If I >= 18 And I < 40 Then MsgBox ("YOU ARE ELIGIBLE FOR INTERVIEW") Else MsgBox ("YOU ARE NOT ELIGIBLE FOR INTERVIEW") End If End Sub

Вам также может понравиться