+ 1
Prime Factorization not printing the last digit
why does my code not showing the last digit of prime factor ex. 20 = 2 * 5 instead 2 * 5 * 2 https://code.sololearn.com/c92LJdByFGH1/?ref=app
7 Answers
+ 1
All your code does is check which prime numbers are the factors. for complete factorization, you should iterate the loop such that instead of checking the divisibility of a prime art the number n, you should let the number n be modified each time the loop iterates. Check for number /(previous divisor) and run the loop for the same divisor until its not divisible.
+ 1
if add while(number != 0) the output doesnt print
+ 1
try to check again my code please
+ 1
can you show me how im confused with that but if i S.O.P the i inside the for loop it will appear 2 5 2 and thats the number i only want to add in prime string = ""; prime = prime + i + "*" ; i want to print out like this 2 * 5 * 2 * but it print 2 * 5 * only
+ 1
Leave the for loop increment instruction blank: for(int i = 2;i <= input_number;).
Then inside the code, add another condition check at the end: {if(input_number % i != 0){i++}}
Then the code should work.
0
Do not increment the number 'i' in the for loop conditions. Only when the remainder is not 0 then only you should increment i. In your case, If the number were 40, it would have given 2 and 4 as factors as there is no check if the divisor was prime.
0
replace "while(input_number != 0)" by "while(input_number != 1)".