Saturday, July 27, 2013

Program to display all prime numbers less than 100

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,f;
for(i=2;i<100;i++)
{
for(j=2;j<i;j++)
{
if(i%j==0)
    {
    f=1;
    break;
    }
else
    f=0;
}
if(!flag)
cout<<i;
}
getch();
}

2 comments:

  1. This code is frequently ask in any examination Check Number is Prime or not in C++ is very simple and easy to write. Using for loop and if else we can write this code. Your code is very simple and easy to understand. Thanks for sharing this article.

    ReplyDelete
  2. A prime number is a whole number greater than 1, which is only divisible by 1 and itself. First few prime numbers are : 2 3 5 7 11 13 17 19 23
    2 is the only even Prime number. Prime number program in C++. Every prime number can represented in form of 6n+1 or 6n-1, where n is natural number. 2, 3 are only two consecutive natural numbers which are prime too.

    ReplyDelete