C++ Program to Print Prime numbers between 1 100


#include<iostream> using namespace std; int main(){ int i,p,n,j; for(i=1;i<=100;i++){ n=i; p=1; j=2; while(j<=n/2){ if(n % j == 0){ p=0; break; } j++; } if(p==1) cout<<n<<","; } return 0; }

Output:-

1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,