answersLogoWhite

0

Private Sub Command1_Click()

Dim x,g,n,i,sum as Integer

n=Val(Text1.Text)

x=0

y=1

Print x

Print y

for i=3 To n

Sum = x + y

Print Sum

x = y

y = Sum

Next i

End Sub

User Avatar

Wiki User

13y ago

Still curious? Ask our experts.

Chat with our AI personalities

MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
More answers

Prime number between 1 to 100

Dim flag As Boolean

flag =

True

BulletedList1.Items.Add(1)

BulletedList1.Items.Add(2)

For i = 1 To 1000

For J = 2 To i - 1

If (i Mod J = 0) Then

flag =

True

Exit For

Else

flag =

False

End If

Next

If flag = False Then

BulletedList1.Items.Add(i)

End If

Next i

User Avatar

Wiki User

12y ago
User Avatar

good question! I'll write it in semi-program lingo, so you can translate it to visual basic language yourself later.

Fibonacci = 1,1,2,3,5,8,13,21 etc.

x = 1

y = 1

print x, print y

loop(parameters) //loop this function

}

z = x+y

print z

x = y

y = z

{

In this, you start with 1 and 1, then add them together and display that number. Then you set y equal to that number, and x equal to the number behind it. then repeat that.

This should give you the Fibonacci sequence.

-Jp

User Avatar

Wiki User

12y ago
User Avatar

Private Sub Command1_Click()

Dim fibonacci(10) As Long

Dim i As Integer

fibonacci(1) = 1

fibonacci(2) = 1

For i = 3 To 10

fibonacci(i) = fibonacci(i - 1) + fibonacci(i - 2)

Next i

For i = 1 To 10

Print fibonacci(i)

Next i

End Sub

User Avatar

Wiki User

12y ago
User Avatar

Here's a simple, recursive Scheme procedure to find the nth Fibonacci number (n >= 0):

(define (fib n)(if (< n 2)n(+ (fib (- n 1)) (fib (- n 2)))))

The same algorithm in C:

unsigned fib(unsigned n) {return (n < 2) ? n : (fib(n - 1) + fib(n - 2));}

Note, there are much more efficient (but less easy to understand) ways of generating this sequence.

User Avatar

Wiki User

12y ago
User Avatar

Dim arr()

ReDim arr(10)

arr(0)=0

arr(1)=1

For k=2 to UBound(arr)

arr(k)=arr(k-1) + arr(k-2)

Next

For k=0 to UBound(arr)

Print arr(k)

Next

User Avatar

Wiki User

11y ago
User Avatar

Public

Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim I, N As Integer

N = InputBox(

"Enter number")

For I = 2 To N - 1

If N Mod I = 0 Then

MsgBox(

"THE NUMBER IS NOT A PRIME NUMBER")

Exit Sub

End If

Next I

If I = N Then

MsgBox(

"THE NUMBER IS A PRIME NUMBER")

End If

End sub

End class

User Avatar

Wiki User

12y ago
User Avatar

Imports System.Console

Module fabonacci

Dim n, a, b, i, c, t As System.Int32

Sub main()

WriteLine("enter the number")

n = Console.ReadLine()

WriteLine("Fabonacci Series ....")

a = 0

b = 1

WriteLine(a)

WriteLine(b)

i = 0

While (i < n - 2)

c = a + b

WriteLine(c)

t = a

a = b

b = c

i = i + 1

End While

ReadLine()

End Sub

End Module

User Avatar

Wiki User

14y ago
User Avatar

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim N, I As Integer

N = Val(TextBox1.Text)

For I = 2 To N - 1

If I Mod N = 0 Then

Label3.Text = "not prime"

Else

Label3.Text = "prime"

End If

Next

End Sub

End Class

User Avatar

Wiki User

12y ago
User Avatar

  1. Let x = 1, let y = 0.
  2. Print x.
  3. Let x = y + x
  4. Let y = x - y
  5. Repeat from 2.

Public Sub Main() Dim X As Integer Dim Y As Integer Dim cnt As Integer 'Our counter. cnt = 1 Do While cnt < 8 Debug.Print X X = Y + X Y = X - Y cnt = cnt + 1 Loop End Sub

User Avatar

Wiki User

12y ago
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program in visual basic of prime numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp