Monday, December 3, 2012

Prime Numbers Between 1 to 100 using c++

This program will print all the prime numbers between 1 to 100.
all the programs are double checked in this site and they are working in visual studio...

#include<iostream>
using namespace std;
int  main()
{
 int i,j,f;
 cout<<"Prime numbers between 1 to 100 are:\n\n";
 for(i=2;i<=100;i++)
 {
  f=0;
  for(j=2;j<i;j++)
  {
   if(i%j==0)
   {
    f=1;
    break;
   }
  }
  if(f==0)
   cout<<i<<" ";
  }
 system("pause");
 return 0;
}

8 comments:

  1. F is the integer used here. Like j and i..i and j is compared to get the prime number..the value of f decides if its a prime number.. :)

    ReplyDelete
  2. F is the integer used here. Like j and i..i and j is compared to get the prime number..the value of f decides if its a prime number.. :)

    ReplyDelete
  3. If I declare f=0 outside the loop,will it make any difference? ?

    ReplyDelete
  4. If I declare f=0 outside the loop,will it make any difference? ?

    ReplyDelete
  5. woooooow 10qqqqqqqqqqqqqqqqqqqqqq
    very help full thankyou sir

    ReplyDelete
  6. wooooooooooooooooow 10 qqqqqqqqqqqqqqq
    very help full thankyou sir

    ReplyDelete