Saturday, February 9, 2013

ISC PRACTICAL QUESTION



S is a string of capital alphabets, parts of which may be enclosed in brackets ( ). S is an invalid string if the brackets are nested. For example : AXB (YPT (COM)FTY) XUP is not a valid string. Write a program to
(1) Check the validity of the input string.
(2) If the string is valid, output the given string omitting the portion enclosed in brackets.

For example : Input string : COM(IP)PUTER IS JUNK (MONK) MACHINE
Output string : COMPUTER IS JUNK MACHINE
If the string is not valid, print the string and a message “Input string is not valid” and stop.

GOOD QUESTION FOR ISC PRACTICAL



Consider the sequence of natural numbers
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, ……….
Removing every second number produces the sequence
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29,,………….
Removing every third number from the above sequence produces
1, 3, 7, 9, 13, 15, 19, 21, 25, 27, ………..
This process continues indefinitely by removing the fourth, fifth,…. And so on, till after a fixed number of steps, certain natural numbers remain indefinitely. These are known as lucky numbers.
Write a program to generate and print lucky numbers less than a given natural number N where n<=50.
SAMPLE
INPUT       : N = 10 OUTPUT  :  THE LUCKY NUMBERS LESS THAN 10 ARE :         1 3 7
INPUT      : N = 25 OUTPUT :  THE LUCKY NUMBERS LESS THAN 25 ARE:          1 3 7 13 19

GOOD QUESTION FOR PRACTICAL EXAM



Numbers have different representations depending on the bases on which they are expressed.
For example in base 3, the number 12 is written as 110 (1*32 + 1*31 + 0*30),
but in base 8 it is written as 14 (1*81 + 4*80).
Consider, for example, the integers 12 and 5. Certainly these are not equal if base 10 is used for each. But suppose 12 was a base 3 number and 5 was a base 6 number then what happens, 12 base 3 = 1*31 + 2*30, or 5 base 6 or 5 base 10 (5 in any base is equal to 5 base 10). So 12 and 5 can be equal if you select the right bases for each of them.
Write a program to input two integers, X and Y, and calculate the smallest base for X and smallest base for Y (likely different from X) so that X and Y represent the same value. The base associated with X and Y will be between 1 and 20 (both inclusive). In representing these numbers the digits 0 to 9 have their usual decimal interpretations. The upper case alphabetic characters A through J represent digits 10 through 19 respectively.
Test your program for the following data and some random data.

SAMPLE DATA :
INPUT :
X = 12, Y = 5
OUTPUT : 12 (base 3) = 5 (base 6)

INPUT : X = 10, Y = A
OUTPUT : 10 (base 10) = A (base 11)

INPUT : X = 12, Y = 34
OUTPUT : 12 (base 17) = 34 (base 5)

INPUT : X = 123, Y = 456
OUTPUT : 123 is not equal to 456 in any base between 2 to 20

INPUT : X = 42, Y = 36
OUTPUT : 42 (base 7) = 36 (base 8)

Decimal to Roman number conversion

import java.util.*;
class dectoroman
{
    public static void main(String arg[])
    {
        Scanner ob = new Scanner(System.in);
        String R[ ]={"C", "XC", "L", "XL", "X", "IX","V", "IV","I"};
        int x[ ]={100,90, 50, 40, 10, 9, 5, 4, 1};
        int d, i;
        String t="";
        System.out.println("Enter an integer number ");
        d=ob.nextInt();
        for(i=0;i
<R.length;i++)

        {    
            while(d<=x[i])
            {
                d = d - x[i];
                t = t + R[i];
            }
        }
        System.out.println("Roman number is = "+ t);
    }
}

Monday, February 4, 2013

ISC Practical 2013 - Expected Questions

ISC Practical ( Expected )

1. Binary Conversions
2. Hamming Distance
3. Mobius function
4. Sorting Rows / Columns of 2D Array
5. Finding maximum and minimum value of a 2D Array
6. Reversing words of a sentence
7. Sorting of words of a sentence

ISC Practical 2013 - Expected Question

Two decimal numbers converted into binary and sum in binary form

import java.util.*;
class BinaryAdd
{
public int n,m,p,q,r;
public void input()
{
// two decimal numbers converted into binary
// and sum is also converted into binary
Scanner br = new Scanner(System.in);
System.out.println(" Input a number n");
n=br.nextInt();
System.out.println(" Input a number m");
m=br.nextInt();
}
public void calculate()
{
p=decbin(n);
q=decbin(m);
System.out.println("Binary value for " + n + " is " + p);
System.out.println("Binary value for " + m + " is " + q);
r=sumbin(m+n);
System.out.println("Sum of two binary number " + p + " and " + q + " is " + r);
}
public int decbin(int x)
{
int a,s=0, i=0;
while(x>0)
{
a=x%2;
s = s + (int)Math.pow(10,i)*a;
x=x/2;
i++;
}
return s;
}
public int sumbin(int x)
{
int a,s=0, i=0;
while(x>0)
{
a=x%2;
s = s + (int)Math.pow(10,i)*a;
x=x/2;
i++;
}
return s;
}
public static void main(String arg[])
{
BinaryAdd ob= new BinaryAdd();
ob.input();
ob.calculate();
}
}

ISC 2013 Practical - Expected Question

Sum of two Binary numbers

import java.util.*;
class BinarySum
{
public int n,m,p,q,r;
public void input()
{
// two binary numbers added by converting into decimal
// and sum then converted into binary
Scanner br = new Scanner(System.in);
System.out.println(" Input a binary number n");
n=br.nextInt();
System.out.println(" Input a binary number m");
m=br.nextInt();
}
public void calculate()
{
p=bintodec(n);
q=bintodec(m);
if(p== -1 || q== -1)
System.out.println("INVALID BINARY VALUE ");
else
{
System.out.println("Binary number " + n + " in decimal is " + p);
System.out.println("Binary number " + m + " in decimal is " + q);
r=sumbin(p+q);
System.out.println("Sum of two binary number " + n + " and " + m + " is " + r);
}
}
public int bintodec(int x)
{
int a,s=0, i=0;
while(x>0)
{
a=x%10;
if(a>1) return -1;
s = s + (int)Math.pow(2,i)*a;
x=x/10;
i++;
}
return s;
}
public int sumbin(int x)
{
int a,s=0, i=0;
while(x>0)
{
a=x%2;
s = s + (int)Math.pow(10,i)*a;
x=x/2;
i++;
}
return s;
}
public static void main(String arg[])
{
BinarySum ob= new BinarySum();
ob.input();
ob.calculate();
}
}

ISC Practical 2013 Expected Question

for Input N=5
Output : Given number 5
Combinations :
1 1 1 1 1
1 1 1 2
1 2 2
1 1 3
1 4
2 3


import java.io.*;
class numcombi
{
String str="";
int a=0;
int b=0;
public void combi() throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a number : ");
int num = Integer.parseInt(br.readLine());
System.out.println("Combinations :");
for(int i=1;i<=num/2;i++)
{
str="";
extract(num,i);
}
}
public void extract(int n, int m)
{
a=m;
str+=" "+a;
b=n-a;
System.out.println(str+" "+b);
if(b<=m)
{
return;
}
extract(b,m);
}
public static void main(String arg[ ]) throws IOException
{
numcombi obj= new numcombi();
obj.combi();
}
}