Design an algorithm to ?nd all the prime factors of a number (as often as they appear in the actual number)?
One example is, for the input value
10, your protocol should record the attitudes 2, 2, and A FEW.
Thanks to your advantage answer in order to my earlier answer.
You might build in that to obtain what you deserve here.
The basic logic could be to start div in 2 as well as keep dividing by simply it until each month longer any divisor.Use a variable quotient in order to store the end result after every single succesful department.Then increment div and continue until until quotient is equal to 1:
int div = 2;
int quo = num; // num is the best starting number
while( quo < 1 )
…if( quo PERCENT div == 0 )
……screen-print div;
……quo = quo/div;
…
…different div++;
Very easy, eh
+add
Why on earth do you suppose of which someone afforded this reply a ‘thumbs down’
++add
The man or women who left that score was variety enough for you to send me a message to point out that my personal while issue is completely wrong.It really should be a <= rather then <.
+++add
Not really my day time.I misinterpreted precisely what he (she) mentioned.It really should be >.
try this
int i;
int tmp=num;
while(tmp>1)
i=2;
while(i<=tmp)
if(tmp%i==0)
bust;
i++;
screen-print i
tmp=tmp/i;
Leave a Reply
You must be logged in to post a comment.