Monday, 29 August 2016

Prime numbers without using loops

void prime(int ans,int count,int num)
{
if(count<=num)
{
printf("%d ",ans-1);
++count;
if(count<=num)
{
printf("%d ",ans+1);
++count;
}
ans=ans<<1;
prime(ans,count,num);

}


}
int main(void) {
// your code goes here
int num;
scanf("%d",&num);
int num1=1,num2=2,num3=3,count=4,ans=6;
printf("%d %d %d ",num1,num2,num3);
prime(ans,count,num);
return 0;
}

No comments:

Post a Comment