Saturday , 27 May 2017
Home » Class 12 » ISC 2014 [Question 1] Practical Paper Solved – Composite Magic Number

ISC 2014 [Question 1] Practical Paper Solved – Composite Magic Number

Click here to download the complete ISC 2014 Computer Science Paper 2 (Practical).

Question:

A Composite Magic number is a positive integer which is composite as well as a magic number.

Composite number:
A composite number is a number that has more than two factors.
For example: 10
Factors are: 1, 2, 5, 10

Magic number:
A magic number is a number in which the eventual sum of the digits is equal to 1
For example: 28=2+8=10=1+0=1

Accept two positive integers m and n, where m is less than n as user input. Display the number of Composite magic integers that are in the range between m and n (both inclusive) and output them along with the frequency, in the format specified below.

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

Example 1:

INPUT:

m = 10
n = 100

OUTPUT:  

THE COMPOSITE MAGIC INTEGERS ARE:
10, 28, 46, 55, 64, 82, 91, 100
FREQUENCY OF COMPOSITE MAGIC INTEGERS IS: 8

Example 2:

INPUT:

m = 1200
n = 1300

OUTPUT:      

THE COMPOSITE MAGIC INTEGERS ARE:
1207, 1216, 1225, 1234, 1243, 1252, 1261, 1270, 1288
FREQUENCY OF COMPOSITE MAGIC INTEGERS IS: 9

Example 3:

INPUT:

m = 120
n = 99

OUTPUT:      

INVALID INPUT

Programming Code:

/**
* The class MagicComposite_ISC2014 inputs two integers and prints all those numbers
* which are composite as well as Magic
* @author : www.javaforschool.com
* @Program Type : BlueJ Program - Java
* @Question Year : ISC Practical 2014 Question 1
*/

import java.io.*;
class MagicComposite_ISC2014
{  
    boolean isComposite(int n) // Function to check for Composite number
    {
        int count=0;
        for(int i=1;i<=n;i++)
        {
            if(n%i==0)
                count++;
        }
        if(count>2)
            return true;
        else
            return false;
    }

    int sumDig(int n) // Function to return sum of digits of a number
    {
        int s = 0;
        while(n>0)
        {
            s = s + n%10;
            n = n/10;
        }
        return s;
    }
    
    boolean isMagic(int n) // Function to check for Magic number
    {
        int a = sumDig(n);
        while(a>9)
        {
            a = sumDig(a);
        }
                    
        if(a == 1)
            return true;
        else
            return false;
    }

    public static void main(String args[])throws IOException
    {
        MagicComposite_ISC2014 ob = new MagicComposite_ISC2014();
        BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
        
        System.out.print("Enter the lower limit(m) : ");
        int m=Integer.parseInt(br.readLine());
        System.out.print("Enter the upper limit(n) : ");
        int n=Integer.parseInt(br.readLine());
        
        int c=0;
        if (m<n)
        {
            System.out.println("The Composite Magic Integers are: ");
            for(int i=m; i<=n; i++)
            {
                if(ob.isComposite(i)==true && ob.isMagic(i)==true)
                {
                    if (c==0) // Printing the first number without any comma
                        System.out.print(i);
                    else
                        System.out.print(", "+i);
                    c++;
                }
            }
            System.out.println("nThe frequency of Composite Magic Integers is : "+c);
        }

        else
            System.out.println("OUT OF RANGE");
    }
}

Output:

Enter the lower limit(m) : 1200
Enter the upper limit(n) : 1300
The Composite Magic Integers are:
1207, 1216, 1225, 1234, 1243, 1252, 1261, 1270, 1288
The frequency of Composite Magic Integers is : 9

Check Also

[Question 2] ISC 2017 Computer Practical Paper Solved – Quiz Result

Solution of Program 2 of ISC 2017 Computer Science Paper 2 (Practical) Exam. Java program to input the answers of each participant row-wise and calculate their marks

21 comments

  1. Sir, is it possible to get data structures as a practical program for 2016 ISC board?

  2. Respected sir/madam….
    how do we solve this program..??
    A string is said to be “unique”, if none of the alphabets present in the string are repeated.Write a program to accept a string and check whether the string is unique or not.
    Sample input:COMPUTER
    Sample output:Unique string

    • import java.util.*;
      class UniqueWord
      {
          public static void main(String args[])throws Exception
          {
              Scanner sc = new Scanner(System.in);
              
              System.out.print("Enter a word : ");
              String s = sc.next();
              int l = s.length();
              
              char ch;
              int f = 0;
              
              for(int i=0; i<l; i++)
              {
                  ch = s.charAt(i);
                  if(s.indexOf(ch)!=s.lastIndexOf(ch))
                  {
                      f = 1;
                  }
              }
              
              if(f == 1)
                  System.out.println("The word is Not Unique");
              else
                  System.out.println("The word is Unique");
          }
      }
          
      
  3. sir how to write an algorithm

  4. Respected Sir/madam
    can u please give me some example questions asked in viva

  5. this program hepled me a lot…

  6. very nice program…

  7. Respected Sir/Maam

    In viva the examiner asked me just one question…..What do we use Nested If.

    I replied: to implement conditions under the conditions.

    is my answer correct

  8. Hi, I got the output and the viva was also okay…but the external did not ask me to take a printout of the output, so I just took a printout of the program…it is clearly specified in the question paper that the output has to be printed out…I am going to lose marks for this right..? 🙁

    • It should have been taken out. But if the examiner marked that you have shown the output, and none of your batch mates took printouts of the output then no need to worry. You won’t lose your marks.

  9. mam today the exam was very fantastic thankyou for all of your help through programs and algorithms.i am very grateful to you

    grateful to you.

  10. Thnx a lot sir!!

  11. the examiner askd me wat is a modifier. can u please answer??

  12. The external asked me only one question in viva..will he give me 1 or 2 marks out of 20?

Leave a Reply to MZA Cancel reply

Your email address will not be published. Required fields are marked *