title: Program to find next immediate prime number
body: <pre><code>void main()    
  {
     int n,i,j,flag=0,out;
  
     clrscr();
  
     printf("enter the num\n");
  
     scanf("%d",&amp;n);
  
     for(i=n+1;i&lt;=100;i++)
     {
  
        flag=0;
  
        for(j=2;j&lt;i;j++)
        {
           if(i%j==0)
           {
              flag=1;
              break;
           }
        }
  
        if(flag==0)
        {
           printf("next prime is:%d",i);
           break;
        }
     }
  
     getch();
  
  }
  </code></pre>
  
  <p>In this code if i entered input as 8 . Then i=9,j=2 
  then 9%2==0 the condition becomes false and 9 will be printed as next prime number which is wrong answer.Please give me correct solution for this program.</p>