malikchandan62
BAN USER#include<stdio.h>
#include<stdlib.h>
int main()
{
int number,x;
int sparse(int); // prototype of function
printf("Enter the number:");
scanf("%d",&number);
while(1)
{
x=sparse(++number);
if(x==1) // means nearest sparse number found
{
printf("%d",number);
break;
}
}
}
int sparse(int number)
{
int binary[100];
int quotient;
int i=1,j;
// 1st convert the number into its binary equivalent
binary[0]=number%2;
quotient=number/2;
while(quotient!=0)
{
binary[i++]=quotient%2;
quotient=quotient/2;
}
/* Need not to reverse the binary[] to get the correct binary number */
// check whether there are two consectives 1 in the representation
for(j=0;j<i-1;j++)
{
if(binary[j]==1 && binary[j+1]==1)
return 0;
}
return 1;
}
put k=4, 6k+1= 25 but 25 is not a prime number
- malikchandan62 October 22, 2015