Q. Write a function(efficient) to find the next prime number after a given number ?

Questions by rameshwar83   answers by rameshwar83

Showing Answers 1 - 4 of 4 Answers

baseersd

  • Jul 24th, 2007
 

#include<stdio.h>
main()
{
int i,j,count,num;

printf("nEnter the number");
scanf("%d",&num);
for(i=num+1;1;i++)
{
 for(j=2,count=0;j<=i;j++)
 {
               if(i%j == 0)
               {
                count++;
               }     
 }
 if(count==1)
 {
  printf("%d",i);
  break;           
 }
}

getch();
}

  Was this answer useful?  Yes

#include<stdio.h>
#include<conio.h>
void main()
{
 int a,i;
clrscr();
printf( " enter the number");
scanf("%d",&a);
for(i=a;i<a+1000;i++)
{
if(i==1||i==2||i==3||i==5||i==7)
{
printf("%d",i);
}
else if(i%2==0||i%3==0||i%5==0||i%7==0)
{
}
else
{
printf("%d",i);
break;
}
}
getch();
}

  Was this answer useful?  Yes

Vishal Bharadwaj

  • Aug 31st, 2018
 

Code
  1. #include <stdio.h>

  2. "Immediate next prime is:-   %d""%d"

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions