This program generates and prints prime numbers between 1 and 100. Here's how it works:
Note that the program is using the fact that a number is prime if it has exactly two divisors, namely 1 and itself.
//Program for prime number between 1-100 #include<iostream> using namespace std; int main() { int n,c=0; for(n=1; n<=100; n++) { for(int i=1; i<=n; i++) { if(n%i==0) c++; } if(c==2) { cout<<n<<endl; } c=0; } return 0; }
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97To download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions