prime factorisation

Hi! Could sommeone help me? I wrote a program that counts prime factors of numbers, do you know what could I do to print only numbers with odd prime factors? I would be grateful for any suggestion :).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  #include<iostream>
#include<fstream>
using namespace std;
int primefactor(int x)
{
    if(x==1){return 1;}
    int num=2;
    while(x%num!=0)
    {
        num++;
    }
    cout<<num<<" ";
    primefactor(x/num);
}
bool read_file(char name[])
{
    ifstream plik;
    int x;
    plik.open(name,ios::in);
    while(true)
    {
        if(!plik.good()) {break;}
        else
        {
         plik>>x;
         cout<<x;
        cout<<" :";
         primefactor(x);
         cout<<"|";
          }
        }

        plik.close();
    }

int main()
{
 read_file("liczby2.txt");
}
n mod 2 is 1 for odd numbers, and 0 for even numbers.

You have another problem though. But first, have you heard of RAII?
https://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization
Topic archived. No new replies allowed.