Please do not blindly copy/paste.Try understanding it.
For a detailed explaination :VIDEO HERE
Please let me know if i should continue making such videos where in i explain the solution.
---------------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<math.h>
int len(int);
int prime(int);
void main()
{
int N;
int i;
scanf("%d",&N);
int r=len(N);
int p=0;
for(i=1;i<=r;i++)
{
int num=N;
int j;
int le=len(N);
for(j=0;j<i;j++)
{
int rem=num%10;
num=(num/10)+(rem*pow(10,le-1));
}
int result=prime(num);
if(result==1)
p++;
}
if(p==r)
printf("Circular prime");
else
printf("Not circular prime");
}
int len(int a)
{
int l=0;
while(a>0)
{
l++;
a/=10;
}
return l;
}
int prime(int n)
{
int c=1;
int i;
for(i=2;i<n;i++)
{
if(n%i==0)
{
c=0;
break;
}
}
return c;
}
For a detailed explaination :VIDEO HERE
Please let me know if i should continue making such videos where in i explain the solution.
---------------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<math.h>
int len(int);
int prime(int);
void main()
{
int N;
int i;
scanf("%d",&N);
int r=len(N);
int p=0;
for(i=1;i<=r;i++)
{
int num=N;
int j;
int le=len(N);
for(j=0;j<i;j++)
{
int rem=num%10;
num=(num/10)+(rem*pow(10,le-1));
}
int result=prime(num);
if(result==1)
p++;
}
if(p==r)
printf("Circular prime");
else
printf("Not circular prime");
}
int len(int a)
{
int l=0;
while(a>0)
{
l++;
a/=10;
}
return l;
}
int prime(int n)
{
int c=1;
int i;
for(i=2;i<n;i++)
{
if(n%i==0)
{
c=0;
break;
}
}
return c;
}
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteGood job checking only till the sqrt of the number for factor that drastically reduces time when dealing with large inputs
Delete