So after a day or two of trying i finally found out how to do this, my question is, is there any way to do this that is more efficient without using the prime function?

#include <iostream>
using namespace std;


      int main()
{
 std::string line;
 
 int i, p, x;
 
 for(i = 3; i <=100; i++) {
       
       for(p=2; p<i; p++)
       {
                if((i%p) == 0) x = 0;
                }
                if(x != 0) cout << i << " is prime\n";
                x = 1;
                }
       
       
        
    
 getline(cin,line);
 cin.get();
 
 return 0;
}

how should i improve my formatting, can you please give me an example... i just get lost of what has to be where when im writing

example. Note placement of braces and spacing. For more information read this by the author of the c++ language.

#include <iostream>
using namespace std;


int main()
{
    std::string line;
 
    int i, p, x;
 
    for(i = 3; i <=100; i++) 
    {     
       for(p=2; p<i; p++)
       {
            if((i%p) == 0) 
                x = 0;
       }
       if(x != 0) 
             cout << i << " is prime\n";
       x = 1;
    }
    getline(cin,line);
    cin.get();
    return 0;
}
This article has been dead for over six months. Start a new discussion instead.