Prime Number

You are given an integer N. You need to print the series of all prime numbers till N.

Input Format
The first and only line of the input contains a single integer N denoting the number till where you need to find the series of prime number.

Output Format
Print the desired output in single line separated by spaces.

Constraints
1<=N<=1000

Source Code:
 #include <stdio.h>  
 int main()  
 {  
   int n,flag,i,j;  
   scanf("%d",&n);  
   printf("2 ");  
   for(i=3;i<=n;i=i+2)  
   {   
     flag=0;  
     for(j=3;j<=i/2;j++)  
     {  
       if(i%j==0){ flag=1;break;}  
     }  
     if(flag==0){printf("%d ",i);}  
   }  
 }  

Comments

Popular posts from this blog

Find Product ! Hacker Earth

Seating Arrangement

Roy and Profile picture