Sunday, March 17, 2013

C++ program to find prime number

C++ program code to find numbers

#include<iostream>
#include<iomanip>
int main(){
    int num,i,count;
 
    for(num = 1;num<=100;num++){
         count = 0;
         for(i=2;i<=num/2;i++){
             if(num%i==0){
                 count++;
                 break;
             }
        }
       
         if(count==0 && num!= 1)
             cout <<  num  << setw(3);
    }
 
   return 0;
}

 

 ---------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------




---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------

No comments:

Post a Comment