Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in VB Net i am trying to find the Prime factorization of a inputted number n ex) 4 = 2 x 2, 16 = 2
in VB Net i am trying to find the Prime factorization of a inputted number "n"
ex) 4 = 2 x 2, 16 = 2 x 2 x 2 x 2.
The code works for 4 = 2 x 2, but when i input 16 it gives me : 2 x 4 x 2 (4 is not prime, should be 2 x 2 )
32 gives me : (2 x 4 x 2 x 2 ).
How could i fix this ? Thank you for your help
Public class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.click Dim n As Long Dim i As Long Dim count As Long n = TextBox1.Text Do Until n = 1 For i = 2 To n If n Mod i = @ Then n = n / i TextBox2.Text += i & "" count += 1 TextBox3. Text = count End If Next i Loop End SubStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started