Navbar

Thursday, 21 March 2019

SOLVED ISC COMPUTER SCIENCE PRACTICAL 2018

COMPUTER SCIENCE PRACTICAL SOLVED QUESTIONS - ISC BOARD 2018 

- MARCH 21, 2019

QUESTION -1

A Goldbach number is a positive even integer that can be expressed as the sum of two odd primes.


Note: All even integer numbers greater than 4 are Goldbach numbers. Example: 6 = 3 + 3
10 = 3 + 7
10 = 5 + 5
Hence, 6 has one odd prime pair 3 and 3. Similarly, 10 has two odd prime pairs, i.e. 3 and 7, 5 and 5.


Write a program to accept an even integer ‘N’ where N > 9 and N < 50. Find all the odd prime pairs whose sum is equal to the number ‘N’.
Test your program with the following data and some random data: Example 1:
INPUT: N = 14
OUTPUT: PRIME PAIRS ARE:
3, 11
7, 7
Example 2: INPUT: N = 30
OUTPUT: PRIME PAIRS ARE
7, 23
11, 19
13, 17
Example 3: INPUT: N = 17
OUTPUT: INVALID INPUT. NUMBER IS ODD.
Example 4: INPUT: N = 126
OUTPUT: INVALID INPUT. NUMBER OUT OF RANGE.

SOLUTION :

import java.util.*;
public class Goldbach
{
    boolean isPrime(int n)
    {
        if(n<=1)        //All numbers that are less than or equal to one are  non-prime
            return false;

        int i;
        for(i=2;i<=n/2;i++)
        {
            if(n%i==0)  //If any number between 2 and n/2 divides n then n is non prime
                return false;
        }
        /*If any return statement is encountered it terminates the function immediately
         * therefore the control will come here only when the above return statements are not executed 
         * which can happen only when the number is a prime number.
         */
        return true;
    }
    
    void print(int n)
    {
        int i, j;
        for(i=2;i<=n;i++)
        {
            for(j=i;j<=n;j++)
            {
                //If i and j are both prime and i+j is equal to n then i and j will be printed
                if(isPrime(i)&&isPrime(j)&&i+j==n)
                System.out.println(i+", "+j);
            }
        }
    }
    public static void main()
    {
        Scanner sc = new Scanner(System.in);
        int n;
        System.out.println("Enter the limit: ");
        n = sc.nextInt();
        if(n%2==1)
        {       //Checking for invalid input and terminating the program
            System.out.println("INVALID INPUT. NUMBER IS ODD.");
            System.exit(0);
        }
        if(n<=9||n>=50)
        {       //Checking for 2nd invalid input and terminating the program
            System.out.println("INVALID INPUT. NUMBER OUT OF RANGE.");
            System.exit(0);
        }
        Goldbach ob = new Goldbach();       //Creating object
        System.out.println("Prime Pairs are: ");
        ob.print(n);
    }
}

------END-----------------------------*-----------------------------------


QUESTION -2

Write a program to declare a matrix A[ ] [ ] of order (M xN) where ‘M’ is the number of rows and ‘N’ is the number of columns such that the values of both ‘M’ and ‘N’ must be greater than 2 and less than 10. Allow the user to input integers into this matrix. Perform the following tasks on the matrix:
(a) Display the original matrix.
(b) Sort each row of the matrix in ascending order using any standard sorting technique.
(c) Display the changed matrix after sorting each row. Test your program for the following data and some random data:

 Example 1:

INPUT:
M = 4
N = 3

Example 2:
INPUT:
M = 3
N =3

Example 3:
INPUT:
M = 11
N = 5

OUTPUT:

MATRIX SIZE OUT OF RANGE

SOLUTION:

import java.util.*;
public class ISC
{
    void sort(int a[])      //Taking  single dimension array as parameter
    {
        int i, j, n = a.length, tmp;        //a.length gives the number of values in the 1D array
        for(i=0;i<n;i++)
        {
            for(j=0;j<n-1-i;j++)            //Sorting using bubble sort technique
            {
                if(a[j]>a[j+1])
                {
                    tmp = a[j];
                    a[j] = a[j+1];
                    a[j+1] = tmp;
                }
            }
        }
    }

    void display(int a[][])     //Taking 2D array as parameter
    {
        int i, j;
        for(i=0;i<a.length;i++)     //a.length here gives the number of rows
        {
            for(j=0;j<a[i].length;j++)  //a[i] gives one row at a time. a[i].length gives the number of values in each row
            {
                System.out.print(a[i][j]+"\t");
            }
            System.out.println();
        }
    }

    void ISC(int a[][])
    {       //As arrays are reference data types any changes made to the formal parameter in this function.
        //Will be reflected in the original parameter.
        int i, j;
        for(i=0;i<a.length;i++)
        {
            sort(a[i]);     //Taking each row and passing each to sort function as a single dimension array
        }
    }

    public static void main()
    {
        Scanner sc = new Scanner(System.in);
        ISC obj = new ISC();
        int a[][], m, n, i, j;
        System.out.println("Enter the number of rows: ");
        m = sc.nextInt();       //Input the size
        System.out.println("Enter the number of columns: ");
        n = sc.nextInt();
        if(m<3||m>9||n<3||n>9)
        {
            System.out.println("Matrix out of range");
            System.exit(0);     //Terminating the program
        }
        a = new int[m][n];      //Allocating memory
        System.out.println("Enter the values for the matrix: ");
        for(i=0;i<m;i++)
        {
            for(j=0;j<n;j++)
            {
                a[i][j] = sc.nextInt();
            }
        }
        System.out.println("Original Matrix: ");
        obj.display(a);     //Displaying array before sorting
        obj.sort2D(a);      //Calling sort function
        System.out.println("Matrix after sorting rows: ");
        obj.display(a);     //Display after sort function has executed
    }
}


--END---------------------------------*-----------------------------------

QUESTION -3

The names of the teams participating in a competition should be displayed on a banner vertically, to accommodate as many teams as possible in a single banner. Design a program to accept the names of N teams, where 2 < N < 9 and display them in vertical order, side by side with a horizontal tab (i.e. eight spaces).

Test your program for the following data and some random data:

Example 1:

INPUT: N = 3
Team 1: Emus
Team 2: Road Rols
Team 3: Coyote

OUTPUT:

SOLUTION:
import java.util.*;
public class ISC2018
{
    public static void main()
    {
        Scanner sc = new Scanner(System.in);
        String ar[];
        int n, i, j;
        System.out.println("Enter the number of names: ");
        n = sc.nextInt();
        ar = new String[n];
        System.out.println("Enter the names: ");
        for(i=0;i<n;i++)
        {
            ar[i] = sc.nextLine();
        }
        int max = 0;

        for(i=0;i<n;i++)
        {
            if(max<ar[i].length())
            max = ar[i].length();       //Finding the length of the string
        }
        System.out.println("OUTPUT:" );
        for(i=0;i<max;i++)
        {
            for(j=0;j<n;j++)
            {
                /*character will be extracted only when i has a value less
                 * than the length of the string else only tabular space will be printed
                 */ 
                if(i<ar[j].length())
                    System.out.print(ar[j].charAt(i)+"\t");
                else
                    System.out.print("\t");
            }
            System.out.println();
        }
    }
}

SOLVED ISC COMPUTER SCIENCE PRACTICAL 2016

COMPUTER SCIENCE PRACTICAL SOLVED QUESTIONS - ISC BOARD 2016 
- MARCH 21, 2019

Question 1:

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

Solution 3:


import java.util.*;
class CircularPrime
{
    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 ob = new CircularPrime();
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a number : ");
        int n = sc.nextInt();
        ob.isCircularPrime(n);
    }
}

*****END*************************

Question 2:


Write a program to declare a square matrix A[][] of order (M x M) where ‘M’ must be greater than 3 and less than 10. 
Allow the user to input positive integers into this matrix.
Perform the following tasks on the matrix:
(a) Sort the non-boundary elements in ascending order
using any standard sorting technique and rearrange 
them in the matrix.
(b) Calculate the sum of both the diagonals.
(c) Display the original matrix, rearranged matrix
and only the diagonal elements of the rearranged
matrix with their sum.

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

Example 1:

INPUT :M = 4
9          2          1          5         
8          13        8          4         
15        6          3          11       
7          12        23        8         

OUTPUT:

ORIGINAL MATRIX
9          2          1          5         
8          13        8          4         
15        6          3          11       
7          12        23        8         
REARRANGED MATRIX
9          2          1          5         
8          3          6          4         
15        8          13        11       
7          12        23        8         
DIAGONAL ELEMENTS
9                                  5         
            3          6                     
            8          13                   
7                                  8                     
SUM OF THE DIAGONAL ELEMENTS = 59


Solution 2:

import java.util.*;
class SortNonBoundary
{
    int A[][],B[],m,n;

    void input() //Function for taking all the necessary inputs
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the size of the square matrix : ");
        m=sc.nextInt();
        if(m<4 || m>10)
        {
            System.out.println("Invalid Range");
            System.exit(0);
        }
        else
        {
            A = new int[m][m];
            n = (m-2)*(m-2);
            B = new int[n]; //Array to store Non-Boundary Elements
             
            System.out.println("Enter the elements of the Matrix : ");
            for(int i=0;i<m;i++)
            {
                for(int j=0;j<m;j++)
                {
                    System.out.print("Enter a value : ");
                    A[i][j]=sc.nextInt();
                }
            }
        }
    }
    void convert(int s)
    {
        int x=0;
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(i != 0 && j != 0 && i != m-1 && j != m-1)
                {
                    if(s==1)
                        B[x] = A[i][j];
                    else
                        A[i][j] = B[x];
                    x++;
                }
            }
        }
    }

    void sortArray() //Function for sorting Non-Boundary 
         elements stored in array B[]
    {
        int c = 0;
        for(int i=0; i<n-1; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                if(B[i]>B[j])
                {
                    c = B[i];
                    B[i] = B[j];
                    B[j] = c;
                }
            }
        }
    }

    void printArray() //Function for printing the array A[][]
    {
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<m;j++)
            {
                System.out.print(A[i][j]+"\t");
            }
            System.out.println();
        }
    }

    void printDiagonal() //Function for printing the 
      diagonal elements and their sum
    {
        int sum = 0;
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(i==j || (i+j)==m-1)
                {
                    System.out.print(A[i][j]+"\t");
                    sum = sum + A[i][j];
                }
                else
                    System.out.print("\t");
            }
            System.out.println();
        }
        System.out.println("Sum of the Diagonal Elements : "+sum);
    }

    public static void main(String args[])
    {
        SortNonBoundary = new SortNonBoundary();
        ob.input();
        System.out.println("*********************");
        System.out.println("The original matrix:");
        System.out.println("*********************");
        ob.printArray(); //Printing the original array
        ob.convert(1); //Storing Non-Boundary elements to a 1-D array
        ob.sortArray(); //Sorting the 1-D array (i.e. Non-Diagonal Elements)
        ob.convert(2); //Storing the sorted Non-Boundary elements back to original 2-D array

        System.out.println("*********************");
        System.out.println("The Rearranged matrix:");
        System.out.println("*********************");
        ob.printArray(); //Printing the rearranged array
        System.out.println("*********************");
        System.out.println("The Diagonal Elements:");
        System.out.println("*********************");
        ob.printDiagonal(); //Printing the diagonal elements and their sum
    }
}


 ****END**************************


Question 3:


Write a program to accept a sentence which may be terminated by either’.’, ‘?’or’!’ only. The words may be separated by more than one blank space and are in UPPER CASE.

Perform the following tasks:
(a) Find the number of words beginning and ending with a vowel.
(b) Place the words which begin and end with a vowel at the beginning, 
followed by the remaining words as they occur in the sentence.

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

Example 1:

INPUT: ANAMIKA AND SUSAN ARE NEVER GOING TO QUARREL ANYMORE.

OUTPUT: NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL= 3
ANAMIKA ARE ANYMORE AND SUSAN NEVER GOING TO QUARREL

Example 2:

INPUT: YOU MUST AIM TO BE A BETTER PERSON TOMORROW THAN YOU ARE TODAY.

OUTPUT: NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL= 2
A ARE YOU MUST AIM TO BE BETTER PERSON TOMORROW THAN YOU TODAY

Example 3:

INPUT: LOOK BEFORE YOU LEAP.
OUTPUT: NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL= 0
LOOK BEFORE YOU LEAP

Example 4:

INPUT: HOW ARE YOU@
OUTPUT: INVALID INPUT

Solution 3:

import java.util.*;
class SENTENCE
{
    boolean isVowel(String w) // Function to check if a word begins and ends with a vowel or not
    {
        int l = w.length();
        char ch1 = w.charAt(0); // Storing the first character
        char ch2 = w.charAt(l-1); // Storing the last character
        if((ch1=='A' || ch1=='E' || ch1=='I' || ch1=='O' || ch1=='U') &&
        (ch2=='A' || ch2=='E' || ch2=='I' || ch2=='O' || ch2=='U'))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public static void main(String args[])
    {
        SENTENCE = new SENTENCE();
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter a sentence : ");
        String s = sc.nextLine();
        s = s.toUpperCase();
        int l = s.length();
        char last = s.charAt(l-1); // Extracting the last character

        /* Checking whether the sentence ends with '.' or '?' or not */
        if(last != '.' && last != '?' && last != '!')
        {
            System.out.println("Invalid Input. End a sentence with         either '.', '?' or '!' only");
        }
        else
        {
            StringTokenizer str = new StringTokenizer(s," .?!");
            int x = str.countTokens();
            int c = 0;
            String w = "", a = "", b = "";

            for(int i=1; i<=x; i++)
            {
                w = str.nextToken(); // Extracting words and saving them               in w

                if(ob.isVowel(w))
                {
                    c++; // Counting all words beginning and ending with         a    vowel
                    a = a + w + " "; // Saving all words beginning and               ending with a vowel in variable 'a'
                }
                else
                    b = b + w + " "; // Saving all other words in variable                'b'  
            }
            System.out.println("OUTPUT : \nNUMBER OF WORDS             BEGINNING AND ENDING WITH A VOWEL = " + c);
            System.out.println(a+b);

        }
    }
}
****END********************