Wednesday , 18 July 2018
Latest Posts
Home » ISC Important Programs » [Question 1] ISC 2016 Computer Practical Paper Solved – Circular Prime

[Question 1] ISC 2016 Computer Practical Paper Solved – Circular Prime

Question:

A Circular Prime is a prime number that remains prime under cyclic shifts of its digits. When the leftmost digit is removed and replaced at the end of the remaining string of digits, the generated number is still prime. The process is repeated until the original number is reached again.
A number is said to be prime if it has only two factors I and itself.

Example:
131
311
113
Hence, 131 is a circular prime.

Test your program with the sample data and some random data:

Example 1

INPUT :N = 197
OUTPUT:
197
971
719
197 IS A CIRCULAR PRIME

Example 2

INPUT :N = 1193
OUTPUT:
1193
1931
9311
3119
1193 IS A CIRCULAR PRIME

Example 3

INPUT :N = 29
OUTPUT:
29
92
29 IS NOT A CIRCULAR PRIME

Programming Code:

```/**
* The class CircularPrime_Q1_ISC2016 inputs a number and
* checks whether it is a Circular Prime or not
* @author : www.guideforschool.com
* @Program Type : BlueJ Program - Java
* @Question Year : ISC Practical 2016 Question 1
*/

import java.util.*;
class CircularPrime_Q1_ISC2016
{
boolean isPrime(int n) // Function for checking whether a number is prime or not
{
int c = 0;
for(int i = 1; i<=n; i++)
{
if(n%i == 0)
c++;
}
if(c == 2)
return true;
else
return false;
}

int circulate(int n) //Function for circulating the digits to form new number
{
String s = Integer.toString(n);
String p = s.substring(1)+s.charAt(0);
int a = Integer.parseInt(p);
return a;
}

void isCircularPrime(int n) //Function to check for circular prime
{
int f = 0,a = n;
do
{
System.out.println(a);
if(isPrime(a)==false)
{
f = 1;
break;
}
a = circulate(a);
}while(a!=n);

if(f==1)
System.out.println(n+" IS NOT A CIRCULAR PRIME");
else
System.out.println(n+" IS A CIRCULAR PRIME");
}

public static void main(String args[])
{
CircularPrime_Q1_ISC2016 ob = new CircularPrime_Q1_ISC2016();
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number : ");
int n = sc.nextInt();
ob.isCircularPrime(n);
}
}```

Output:

Enter a number : 87
87
87 IS NOT A CIRCULAR PRIME

Enter a number : 1193
1193
1931
9311
3119
1193 IS A CIRCULAR PRIME

Enter a number : 123
123
231
312
123 IS NOT A CIRCULAR PRIME

ISC 2017 Computer Science Solution + Examiner’s Comments – From the Council

Solution of ISC 2017 Computer science Paper as provided by the Council for the Indian School Certificate Examinations.