0% found this document useful (0 votes)
14 views2 pages

Batch 2 ND

Good

Uploaded by

shikharnigam2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Batch 2 ND

Good

Uploaded by

shikharnigam2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Q.1.

Given a number , we can form a number chain by :


1. Arranging its digits in descending order.
2. Arranging its digits in ascending order.
3. Subtracting the number obtained in (2) from the number obtained (1) to form a new number.
4. And repeat these steps unless the new number has already appeared in the chain.

Note that 0 is a permitted digit. The number of distinct number in the chain is the length of the chain.
You are to write a program that reads numbers and outputs the number chain and the length of that chain
for each number read.

Sample Input : 1234

Sample Output :
4321 – 1234 = 3087
8730 – 378 = 8352
8532 – 2358 = 6174
7641 – 1467 = 6174

Chain length = 4

******Q.2
Write a program to declare a matrix A[ ][ ] of order (M x N) where M is the number of rows and N is
the number of columns such that M and N must be greater than 2 and less than 20. Allow the user to
input integers into this matrix. Display the appropriate error message for an invalid input. Perform the
following tasks:
a) Display the input matrix
b) Rotate the inputted matrix row -wise upward.
c) Display the rotated matrix.

Example 1
INPUT : M = 3, N=3
24 16 9
18 12 7
1 6 4

OUTPUT : ORIGINAL MATRIX 24 16 9


18 12 7
1 6 4

ROTATED MATRIX 18 12 7
1 6 4
24 16 9
Example 2
INPUT : M=23
OUTPUT : Not in Range

Q.3. Given an array of N positive integers and another number X. Determine


whether or not there exists two elements in array whose sum is exactly X. Display
the sum also.

Sample Input : N = 6 , X = 16
Arr[ ] = { 1, 4, 45, 6, 10, 8}

Sample Ouput : Yes . Arr [3] + Arr [4] = 6+10 = 16

Sample Input : N = 5 , X = 10
Arr[ ] = { 1, 4, 45, 6, 10, 8}

Sample Ouput : Yes . Arr [2] + Arr [4] = 4+6 = 10

You might also like