TAB

One of the works done by our Robotics and Machine Learning division,
SELF-LEVELING QUADCOPTER
Arduino based Quadcopter.
Self-leveling is acheived by the aligning the quadcopter using the readings from the gryo as well as the accelerometer.
A four channel RC transmitter is used to control the movement of the quadcopter when in flight. Kindly subscribe to our YouTube Channel and stay tuned.

Tuesday 26 January 2016

PRACTICE PROBLEMS 2 (24-1 to 31-1) : CIRCULAR PRIMES

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;
}

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Good job checking only till the sqrt of the number for factor that drastically reduces time when dealing with large inputs

      Delete