Full Range

Call me (USA Free)

Saturday 14 February 2015

2014 ISC COMPUTER SCIENCE PRACTICAL SOLVED PAPER

1 comment
  1. Question 1

    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 which 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 digitd 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 frequency, in the format specified below: 

    Example:
    Input: m=10
    n=100
    OUTPUT:
    The composite magic numbers are 10,28,46,55,64,82,91,100
    Frequency of composite magic numbers: 8

    Input: m=120
    n=90
    OUTPUT:
    Invalid input
import java.io.*;
public class CompositeMagicNumber
{
    public static void main(String args[])throws Exception
    {
        BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the lower limit:");
        int m=Integer.parseInt(stdin.readLine());
        System.out.println("Enter the upper limit:");
        int n=Integer.parseInt(stdin.readLine());
        if(m<n)
        {
            int mag[]=new int[n];
            int count=0;
             for(int i=m;i<=n;i++) //checking for composite
             {
                 int flag=0;
                  for(int j=2;j<i;j++)
                   {
                       if(i%j==0)
                        {
                            flag=1;
                            break;
                        }
                    }
                    int num=i,sum=0;
                    while(num>0) //checking for magic number
                     {
                         sum=sum+(num%10);
                         num=num/10;
                          if(num<1&&sum>9)
                           {
                               num=sum;
                               sum=0;
                            }
                    }
                    if(flag==1&&sum==1)
                     {
                         mag[count]=i;
                         count++;
                     }
                    
              }
               if(count>0)
                {
                   System.out.println("THE COMPOSITE MAGIC NUMBERS ARE:");
                     for(int k=0;k<count-1;k++)
                      {
                        System.out.print(mag[k]+",");
                      }
                      System.out.print(mag[count-1]);
                       System.out.println();
                 }
                 System.out.println("FREQUENCY OF COMPOSITE MAGIC INTEGERS IS:"+count);
         }//closing of first if loop
          else
             System.out.println("INVALID INPUT");
    }
}

Question 2
Write a program to declare a square matrix A[][] of order MXM where M is an positive integer and represents row and column. M should be greater than 2 and less than 10.Accept the value of M from user. Display an appropriate message for invalid input.
Perform the following task:
a) Display the original matrix
b) Check if the given matrix is symmetric or not. If the element of the ith row and jth column is same as element of the jth row and ith column,.
c)Find the sum of the left and right diagonal of the matrix and display them

Example 1:
INPUT:
M=3
1 2 3
2 4 5
3 5 6
OUTPUT:
Original matrix
1 2 3
2 4 5
3 5 6
The given matrix is symmetric
Sum of the left diagonal=11
Sum of the right diagonal=10
Example 2:
INPUT: M=4
OUTPUT:
Original matrix:
7 8 9 2
4 5 6 3
8 5 3 1
7 6 4 2

The given matrix is not symmetric
Sum of the left diagonal=17
Sum of the right disgonal=20

Example 3:
INPUT: M=12
OUTPUT:
Matrix size is out of range

import java.io.*;
public class SymmetricMatrix
{
    public static void main(String args[])throws Exception
    {
        BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the number of rows and columns:");
        int m=Integer.parseInt(stdin.readLine());
        if(m>2&&m<10)
         {
           int max[][]=new int[m][m];
           int flag=0;
           for(int i=0;i<m;i++)  //entering matrix elements
            {
                for(int j=0;j<m;j++)
                 {
                   max[i][j]=Integer.parseInt(stdin.readLine());  
                }
            }
           System.out.println("ORIGINAL MATRIX");
            for(int i=0;i<m;i++)  //displaying the original matrix
            {
              for(int j=0;j<m;j++)
                 {
                   System.out.print(max[i][j]+"\t");
                }
                System.out.println();
            }
            for(int i=0;i<m;i++)  //checking for symmetric matrix
            {
              for(int j=0;j<m;j++)
                 {
                     if(max[i][j]!=max[j][i])
                       {
                           flag=1;
                           break;
                        }
                    }
            }
            if(flag==0)
             System.out.println("THE GIVEN MATRIX IS SYMMETRIC");
            else
              System.out.println("THE GIVEN MATRIX IS NOT SYMMETRIC");
          int suml=0,sumr=0;
           for(int i=0;i<m;i++) //finding sum of left diagonal
             {
              suml+=max[i][i];
            }
            int j=m-1;
            for(int i=0;i<m;i++,j--)  //finding sum of right diagonal
             {
                 sumr+=max[i][j];
             }
             System.out.println( suml);
              System.out.println( sumr);
            }
        }
    }
             
              
              
            
            
            
If You Enjoyed This, Take 5 Seconds To Share It

1 comment: