Share this:

 ISC 2015 Computer Practical Paper  Solved

Question 1:

Given two positive numbers M and N, such that M is between 100 and 10000 and N is less than 100. Find the smallest integer that is greater than M and whose digits add up to N. For example, if M = 100 and N = 11, then the smallest integer greater than 100 whose digits add up to 11 is 119.

Write a program to accept the numbers M and N from the user and print the smallest required number whose sum of all its digits is equal to N. Also, print the total number of digits present in the required number. The program should check for the validity of the inputs and display an appropriate message for an invalid input.

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

Example 1

INPUT :
M = 100
N = 11

OUTPUT :
The required number = 119
Total number of digits = 3

Example 2

INPUT :
M = 1500
N = 25

OUTPUT :
The required number = 1699
Total number of digits = 4

Example 3

INPUT :
M = 99
N = 11

OUTPUT :
INVALID INPUT

Example 4

INPUT :
M = 112
N = 130

OUTPUT :
INVALID INPUT

ecolebooks.com

Solution 1;
import java.util.*;
class Number
{
int sumDig(long n)
{
int sum = 0, d;
while(n>0)
{
d = (int)(n%10);
sum = sum + d;
n = n/10;
}
return sum;
}

int countDig(long n)
{
String s = Long.toString(n);
int len = s.length();
return len;
}

public static void main()throws Exception
{
question ob = new question();
Scanner sc = new Scanner(System.in);
System.out.print(“Enter a value of ‘m’ from 100 to 10000 : “);
int m = sc.nextInt();
System.out.print(“Enter a value of n from 1 to 99 : “);
int n = sc.nextInt();

if(m<100 || m>10000 || n<1 || n>99)
{
System.out.println(“Invalid Input”);
}
else
{
long i = (long)m;
while(ob.sumDig(i)!=n)
{
i=i+1;
}
System.out.println(“The required number = “+i);
System.out.println(“Total number of digits = “+ob.countDig(i));
}
}
}
Output 1:
Enter a value of ‘m’ from 100 to 10000 : 1500
Enter a value of ‘n’ from 1 to 99 : 25
The required number = 1699
Total number of digits = 4

Output 2:
Enter a value of ‘m’ from 100 to 10000 : 100
Enter a value of ‘n’ from 1 to 99 : 20
The required number = 299
Total number of digits = 3

Output 3:
Enter a value of ‘m’ from 100 to 10000 : 112
Enter a value of ‘n’ from 1 to 99 : 130
Invalid Input
————end———————

Question 2:

Write a program to declare a square matrix A[ ][ ] of order MxM where ‘M’ is the number of rows and the number of columns, such that M must be greater than 2 and less than 10. Accept the value of M as user input. Display an appropriate message for an invalid input. Allow the user to input integers into this matrix. Perform the following tasks:

(a) Display the original matrix.
(b) Rotate the matrix 90° clockwise as shown below:
Original matrix       Rotated matrix
1 2 3                          7 4 1
4 5 6                          8 5 2
7 8 9                          9 6 3
(c) Find the sum of the elements of the four corners of the matrix.

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

Example 1

INPUT :

M = 3
1 2 3
4 5 6
7 8 9

OUTPUT :

ORIGINAL MATRIX
1 2 3
4 5 6
7 8 9
MATRIX AFTER ROTATION
7 4 1
8 5 2
9 6 3
Sum of the corner elements = 20

Example 2

INPUT :

M = 3

1 2 3
4 5 6
7 8 9

OUTPUT :

ORIGINAL MATRIX
1 2 3
4 5 6
7 8 9

MATRIX AFTER ROTATION

7 4 1
8 5 2
9 6 3
Sum of the corner elements = 18

Example 3

INPUT :
M = 14

OUTPUT :
SIZE OUT OF RANGE

Example 4

INPUT :
M = 112
N = 130

OUTPUT :
INVALID INPUT

Solution:

import java.util.*;
class mat
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print(“Enter the size of the matrix : “);
int m=sc.nextInt();
if(m9)
System.out.println(“Size Out Of Range”);
else
{
int A[][]=new int[m][m];

/* Inputting the matrix */
for(int i=0;i




Share this:


subscriber

Leave a Reply

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

Accept Our Privacy Terms.*