i have the following problem to solve.... im unable even to start with an idea....can anybody help me giving an idea how to do this problem?
the problem is:
___*****____
Write a C++ program that factorize an integer n into p and q.
Step1. reads an integer n from the keyboard.
Step2. Write a for loop as below to check if there is any factor j > 1.
1 2 3 4 5 6 7 8
for (int j = 2; j <= square root of n; j ++)
{
If (n % j == 0)
{
factorizable = true;
break;
}
}
Step3. If there is no such factor, print the message n is not factorizable. If there is such a factor j,
check programmatically if j is a prime and n / j is a prime Also check if j and n / j are the same.
done.... step 2 is giving me nothing..... its bool variable in it. whenever the if condition is true, all the loops break.... and there is true in bool variable... now im confused how to use "factorizable"..
(if i sound stupid, sorry me.... im trying to learn programming :P)
What exactly about the bit of code you've been given is confusing? The loop? The variable 'factorizable'? Post carefully what you think it does logically and we can help you correct anything that is wrong.
A bool is simply a variable that can be either "true" or "false". It cannot have any other value.
Here, your "factorizable" variable is indicating whether or not the number 'n' can be factored. If "factorizable" is true, then that means n can be factored. If false, it means n cannot be factored.
By the way in my opinion the assignment is stupid because j will be always a prime number.:) So what is needed to be done is checking whether n / j is also a prime number.