# Thread: Jumping into C++ problems

1. ## Jumping into C++ problems

Hi, I have written the code of the question "Design a program that finds all numbers from 1 to 1000 whose prime factors, when addedtogether, sum up to a prime number (for example, 12 has prime factors of 2, 2, and 3, which
sum to 7, which is prime). Implement the code for that algorithm."
the code is
Code:
```

#include <iostream>
using namespace std;

bool isdivisible(int z,int i)
{
return z%i==0;
}
bool (isprime (int z))
{
for (int h=2;h<z;h++)
{

if (isdivisible(z,h))
{

return false;

}
}

return true;

}

int main()
{

for ( int k = 2;k<10; k++)
{
int i=2;
int y=0;
int x;
x=k;

while(i<=x)
{
if (x%i==0)
{
x=x/i;
y=y+i;

}
else
{i++;}
}

int z;
z=x+y-1;

if (isprime(z))
{
cout<<k<<endl;
}

}
}```
the problem is that the console window cant display all the results. It omits the 1st few result. How can I increse the space so that it can display all the results?

2. I gave you a link that describes how to write to a file in this thread: A simple C++ problem

3. Originally Posted by Shakti
I gave you a link that describes how to write to a file in this thread: A simple C++ problem

I have done what it says like this, nothing happens,

Code:
```#include <fstream>
#include <iostream>

using namespace std;

bool isdivisible(int z,int i)
{
return z%i==0;
}
bool (isprime (int z))
{
for (int h=2;h<z;h++)
{

if (isdivisible(z,h))
{

return false;

}
}

return true;

}

int main()
{

for ( int k = 2;k<10; k++)
{
int i=2;
int y=0;
int x;
x=k;

while(i<=x)
{
if (x%i==0)
{
x=x/i;
y=y+i;

}
else
{i++;}
}

int z;
z=x+y-1;

if (isprime(z))
{   char str[10];
ofstream file ("example");
file<<z;
file.close();
}

}
}```

4. Originally Posted by Tamim Ad Dari
the problem is that the console window cant display all the results. It omits the 1st few result. How can I increse the space so that it can display all the results?
You can pipe the output to a pager, like "more" or "less" as in:
\$program | more

5. I think the problem lies in your algorithm,,,the console window is capable of displaying thousands of values,..let me check it out

6. Originally Posted by Tamim Ad Dari
I have done what it says like this, nothing happens,