Monday, November 9, 2009

Print all Prime Numbers in given range

Print all Prime Numbers in given range

#include <iostream>

using namespace std;

// Program to print Prime Numbers
int main()
{
        int n,i=1, j, c;
        n = 100;
        while(i <= n)
        {
                c=0;
                for(j=1; j<=i; j++)
                {
                        if(i%j ==0)
                                c++;
                }
                if(c == 2)
                printf("%d\n",i);
                i++;
        }
}

No comments:

Post a Comment