Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Print prime numbers from 1 to 100 in C++
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <iostream>
#include<cmath>
using namespace std;

int main()
{ cout << "Prime Numbers between 1 and 100 are:\n";

for(int i=2;i<=100;++i) //loop to check for each number in the range

{ int ctr=0; //to maintain factor count

for(int j=2;j<=sqrt(i);++j) //checking for factors

{ if(i%j==0)

ctr=1; //increasing factor count when found

}

if(ctr==0) //checking and printing prime numbers

cout<<i<<" ";

}

return 0;

}