COMPUTER SCIENCE PRACTICAL SOLVED QUESTIONS - ISC BOARD 2018
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
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:
Test your program with the following data and some random data: Example 1:
INPUT: N = 14
OUTPUT: PRIME PAIRS ARE:
3, 11
7, 7
OUTPUT: PRIME PAIRS ARE:
3, 11
7, 7
Example 2:
INPUT: N = 30
OUTPUT: PRIME PAIRS ARE
7, 23
11, 19
13, 17
OUTPUT: PRIME PAIRS ARE
7, 23
11, 19
13, 17
Example 3:
INPUT: N = 17
OUTPUT: INVALID INPUT. NUMBER IS ODD.
OUTPUT: INVALID INPUT. NUMBER IS ODD.
Example 4: INPUT: N = 126
OUTPUT: INVALID INPUT. NUMBER OUT OF RANGE.
OUTPUT: INVALID INPUT. NUMBER OUT OF RANGE.
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);
}
}
-----------------------------------*-----------------------------------
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:
(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
M = 4
N = 3
Example
2:
INPUT:
M = 3
N =3
INPUT:
M = 3
N =3
Example
3:
INPUT:
M = 11
N = 5
OUTPUT:
MATRIX SIZE OUT OF RANGE
INPUT:
M = 11
N = 5
OUTPUT:
MATRIX SIZE OUT OF RANGE
import
java.util.*;
public
class TwoDArr
{
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 sort2D(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);
TwoDArr obj = new TwoDArr();
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
}
}
-----------------------------------*-----------------------------------
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:
import
java.util.*;
public
class ISC2018Q3
{
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();
}
}
}
wow
ReplyDeleteGreat:)
ReplyDeleteawesome man!!!!!!!!!!
ReplyDeletethanku soo much for ur help!!!
ReplyDeleteohhhh!!!!!!!!
ReplyDeleteThis helped me a lot.
ReplyDeleteThanx a lot
ReplyDeleteFine
ReplyDeleteThanks
ReplyDeleteThank you so much for your help :)
ReplyDeleteSir,there is a mistake in question no. 3,whe we are entering the value of n the program is getting printed only for 2 string value, so if we use the statement n=sc.nextInt()+1; thuis statement will let the program to get the exact output,so kindly change the program
ReplyDeleteU were correct u made my practical day easy thanks
DeleteNice
DeleteYes I agree with you ..u r correct...
ReplyDeleteGreat post.
ReplyDeletehttps://knowyourmeme.com/users/josephlowe
Great post.
ReplyDeletehttps://www.codecademy.com/profiles/larrywagner6140001425
Very Much Helpful
ReplyDeleteThanks a lot
thank u
ReplyDeleteZiyyaras’ ICSE online tuition for school children taking education as per ICSE board in India supports them to get all the doubts clear in addition to completing the syllabus on time. In case, you look for the best online ICSE tutor at home, you must enroll at our portal at the earliest.
ReplyDeleteThanks for providing the useful content. Ziyyara’s altered online ICSE home tuition classes and dedicated tutors address our students’ unique learning styles. Our ICSE online tuition tutor knows the art of creating even the boring and difficult chapters that look interesting. Thus more students have started taking online courses so that they can easily understand the curriculum taught by the ICSE board.
ReplyDelete