Prime numbers program

后端 未结 14 1503
无人及你
无人及你 2021-01-07 00:27

I\'m currently trying out some questions just to practice my programming skills. ( Not taking it in school or anything yet, self taught ) I came across this problem which re

14条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-07 01:09

    Here is my code. When working on a big number, it's very slow! It can calculate all prime numbers with in the number you input!

    #include 
    #include 
    #include 
    using namespace std;
    
    int main()
    {
        int m;
        int n=0;
        char ch;
        fstream fp;
        cout<<"What prime numbers do you want get within?  ";
        if((cin>>m)==0)
        {
                     cout<<"Bad input! Please try again!\n";
                     return 1;
        }
        if(m<2)
        {
            cout<<"There are no prime numbers within "<(sqrt(i))+1;
                fp.seekg(0,ios::beg);
                fp>>j;
                for(;j>j)==NULL)
                        {
                            j=3;
                        }
                    }
                }
                if(j>=sq)
                {
                    fp.seekg(0,ios::end);
                    fp<

提交回复
热议问题