Monday, 30 January 2017

Program to check Upper Triangular matrix

What is Upper Triangular Matrix?  An upper triangular matrix is a square matrix in which all theelements below the diagonal are zero. We consider a Matrix U with ‘i’ rows and ‘j’ columns, thenmathematically we represent the upper triangular matrix as

                                                             upper-triangular-matrix-formula.gif (130×42)
In another word strictly upper triangular matrix is an upper triangular matrix having 0’s along the diagonal as well, i.e., U(ij)=0 for i>=j.
                                                             UpperTriangularMatrix.gif (147×76)

spiral matrix






Outer spiral matrix– arrows are from boundary to core element. Inner Spiral matrix– Arrows are from core elements to boundary elements.

Program for Matrix Multiplication in JAVA...

Matrix Multiplication: Here is given a Java Program for Matrix Multiplication also call matrix product. In other words, Let the two matrix to be multiplied be A and B. Let A is an n × m order matrix and B is an m × p order matrix, their matrix product A*B is an n × p order matrix, in which the m entries across the rows of A are multiplied with the m entries down the columns of B.

Steps for Matrix Multiplication in Java:

Step 1: Make sure that the the number of columns in the 1st matrix equals the number of rows in the 2nd matrix.
Step 2: Multiply the elements of each row of the first matrix by the elements of each column in the second matrix.
Step 3: Add the products.




Iteration 1
Multiplication of matrix A’s first row with each element of matrix B’s all columns,
1*1+2*5, 1*2+2*6, 1*3+2*7, 1*4+2*8
Iteration 2
Multiplication of matrix A’s second row with each element of matrix B’s all columns,
3*1+4*5, 3*2+4*6, 3*3+4*7, 3*4+4*8
Iteration 3
Multiplication of matrix A’s third row with each element of matrix B’s all columns,
5*1+6*5, 5*2+6*6, 5*3+6*7, 5*4+6*8
Iteration 4
Add all the multiplication and get the matrix with an order 3*4.

Mobius Function of number...

The MOBIUS function µ(n) for a natural number N is defined as follows:
µ(n) = 1 if n is a square free positive integer with an even number of prime factors.
µ(n) = 0 if n has a squared prime factor.
µ(n) = -1 if n is a square free positive integer with an odd number of prime factors.
Example:
µ(26)=1                ( for 26 = 2 * 13     µ(26) = ( -1)^2= 1 )
µ(19)=-1               ( for 19 = 19     µ(19) = ( -1)^1= -1 )
µ(62)=1                ( for 62 = 2 * 31     µ(61) = ( -1)^2= 1 )
µ(28)=0                ( for 28 = 2 * 2 * 7     µ(28) = 0 for 2 appears two times )

Thursday, 19 January 2017

Days Elapsed...

Write a program to input two valid dates, each comprising of day          (2 digits), Month (2 digits) and year (4 digits) and calculate the days elapsed between the two dates. Test your program for the following data values:
i) FIRST DATE :              DAY : 24
                                      MONTH: 09
                                      YEAR: 1960
   SECOND DATE :           DAY : 08
                                      MONTH: 12
                                      YEAR: 1852
       
ii) FIRST DATE :             DAY : 10
                                      MONTH: 01
                                      YEAR: 1852
   SECONDDATE :             DAY : 16
                                       MONTH: 10

                                       YEAR: 1952                

Graph...

A sentence is terminated by either “ . ” , “ ! ” or “ ? ” followed by a space. Input a piece of text consisting of sentences. Assume that there will be a maximum of 10 sentences in a block.
Write a program to:
(i)Obtain the length of the sentence (measured in words) and the frequency of vowels in each sentence.
(ii)Generate the output as shown below using the given data
INPUT                   HELLO! HOW ARE YOU? HOPE EVERYTHING IS FINE. BEST OF LUCK.
OUTPUT      Sentence No. of Vowels No. of words
Sentence                No. of vowels          No. of words
1                           2                           1
2                           5                           3
3                           8                            4
4                           3                            3
Sentence                                   No. of words/vowels
1                                              VVVVVV
1                                              WWW
2                                              VVVVVVVVVVVVVVV
2                                              WWWWWWWWWWWW
3                                              VVVVVVVVVVVVVVVVVVVVVVVV
3                                              WWWWWWWWWWWWWWW
4                                              VVVVVVVVV
4                                              WWWWWWWWWWWW

                   Scale used 1:3

Matrix...

Write a program to declare a matrix A [][] of order (MXN) where ‘M’ is the number of rows and ‘N’ is the number of columns such that both M and N must be greater than 2 and less than 20. Allow the user to input integers into this matrix. Perform the following tasks on the matrix:

a)   Display the input matrix
b)   Find the maximum and minimum value in the matrix and display them along with their position.
c)    Sort the elements of the matrix in ascending order using any standard sorting technique and rearrange them in the matrix.
d)   Output the rearranged matrix.

INPUT:         M=3            N=4

Entered values: 8, 7, 9, 3, -2, 0, 4, 5, 1, 3, 6, -4
Original matrix:
8  7  9  3
-2  0  4  5
1  3  6  -4


Largest Number: 9  Row: 0                   Column: 2   
Smallest Number: -4       Row=2                  Column=3
Rearranged matrix:
-4  -2  0  1
3  3  4  5
6  7  8  9
Input:                    M=3            N=22

Output:        Size out of range

Reverse...

The input here will consists of a number of lines of English text consisting of the letters of the English alphabet, the punctuation marks (‘) apostrophe, (.) full stop, (,) comma, (;) semicolon, (:) colon and white space characters (blank, new line). Your task is to print the words of the text in reverse order without a punctuation mark other than blanks. For example consider the following input text:
‘This is a sample piece of text to illustrate this problem. If you are smart you will solve this right’.
 The corresponding output would read as:
‘right this solve will you smart are you If problem this illustrate to text of piece sample a is This’.
That is, the lines are printed in reverse order. Note: Individual words are not reversed.
Input format
The first line of input contains a single integer N( < = 20), indicating the number of lines in the input. This is followed by N lines of input text. Each line should accept a maximum of 80 characters.
Output format
Output the text containing the input lines in reverse order without punctuations except blanks as illustrated above.
Test your program for the following data and some random data.
Input:                    Emotions, controlled and directed to work, is character. By Swami Vivekananda.
Output:                  Vivekananda Swami By character is work to directed and controlled Emotions.

Input :                   Do not judge a book by its cover.
Output:                  cover its by book a judge not Do.

Wondrous Square..

A wondrous square is an n by n grid which fulfils the following conditions:
    (i) It contains integers from 1 to n2, where each integer appears only once.
    (ii) The sum of integers in any row or column must add up to 0.5 * n * (n2 + 1).
For example the following grid is a wondrous square where the sum of each row or column is 65 when n = 5 :
                   17      24      2        8        15
 23      5        7       14      16
 4       6       13       20      22
                   10       12      19      21      3
 11      18      25      2        9
Write a program to read n (2 < = n < = 10) and the values stored in these n by n cells and output if the grid represents a wondrous square or not.
Also output all the prime numbers in the grid along with their row index and column index as shown in the output. A natural number is said to be prime if it has exactly two divisors. E.g. 2, 3, 5, 7, 11,.......
The first element of the given grid i.e. 17 is stored at row index 0 and column index 0 and the next element in the row i.e. 24 is stored at row index 0 and column index 1.
Test your program for the following data and some random data.
SAMPLE DATA:
      INPUT :                     N = 4
16       15      1        2
 6        4       10      14
                        9         8        12      5
                        3         7       11      13
OUTPUT:               YES IT REPRESENTS A WONDROUS SQUARE.



 PRIME                    ROW INDEX                              COLUMN INDEX
 2                                    0                                     3
 3                                    3                                    0
 5                                    2                                    3
 7                                    3                                    1
11                                   3                                    2
13                                   3                                    3
Input           N=4
                   1        2        4
                   3        7       5
                   8        9        6
Output                   not a wondrous square
PRIME                     ROW INDEX                              COLUMN INDEX
 2                                    0                                     0

 2                                    1                                     1

Kaprekar Number...

A positive whole number 'n' that has 'd' number of digits is squared and split into 2 pieces, a right hand piece that has 'd' digits and a left hand piece that has remaining 'd' or 'd-1' digits. If sum of the pieces is equal to the number then it’s a kaprekar number. The first few Kaprekar numbers are: 9, 45, 297…..

For example 297 is a kaprekar number because:
2972 =88209, right hand piece of 88209=209 and left hand piece of 88209=88
Sum=209+88=297 , i.e. equal to the number.

Given the two positive integers p and q, where p < q. Write a program to determine how many kaprekar numbers are there in the range between 'p' and 'q'(both inclusive )and output them.

The input contains two positive integers p and q. Assume p<5000 and q<5000. You are to output the number of kaprekar numbers in the specified range along with their values in the format specified below:
SAMPLE DATA:
INPUT:                  p=1
Q=1000
OUTPUT:     THE KAPREKAR NUMBERS ARE:
1, 9, 45, 55, 99, 297, 999

FREQUENCY OF KAPREKAR NUMBERS IS:8

Bank...

A bank intends to design a program to display the denomination of an
input amount, upto 5 digits. The available denomination with the bank are
of rupees 1000, 500, 100, 50, 20, 10, 5, 2 and 1.

Design a program to accept the amount from the user and display the
break-up in descending order of denominations. (i,e preference should
be given to the highest denomination available) along with the total
number of notes. [Note: only the denomination used should be displayed].
Also print the amount in words according to the digits.

INPUT:                            14836
OUTPUT:               ONE FOUR EIGHT THREE SIX
DENOMINATION:
1000   X       14     =       14000
500    X      1       =       500
100    X      3       =       300
50      X       1       =       50
5        X       1       =       5
1        X       1       =       1

Total                                                  =       14856

Total number of notes                                    =       21

Time to Words...

Given a time in numbers we can convert it into words. For example :
5 : 00                      five o’clock
5 : 10            ten minutes past five
5 : 15                     quarter past five
5 : 30                     half past five
5 : 40           twenty minutes to six
5 : 45                     quarter to six
5 : 47                    thirteen minutes to six
Write a program which first inputs two integers, the first between 1 and 12 (both inclusive) and second between 0 and 59 (both inclusive) and then prints out the time they represent, in words.Your program should follow the format of the examples below.

SAMPLE DATA :
 INPUT :                TIME :         3,0
OUTPUT :              3 : 00 Three o’ clock
INPUT :                 TIME :         7,29
OUTPUT :              7 : 29 Twenty nine minutes past seven
INPUT :                 TIME :         6,34
OUTPUT :              6 : 34 Twenty six minutes to seven
INPUT :                 TIME :         12,1
OUTPUT :              12 : 01 One minute past Twelve
 INPUT :                TIME : 12,45
OUTPUT :              12 : 45 Quarter to One
INPUT :                 TIME : 10,59
OUTPUT :              10 : 59 One minute to Eleven
INPUT :                 TIME : 14,60
OUTPUT :              Incorrect Input

Test your program for the data values given in the examples above and some random data.

Number to words...

Write a program to input a natural number less than 1000 and display it in words. Test your program for the given sample data and some random data.
Input:          29
Output:                  TWENTY NINE
Input:          17
Output:        SEVENTEEN
Input:                    119
Output:                  ONE HUNDRED AND NINETEEN
Input:          220

Output:        TWO HUNDRED AND TWENTY


Prime Palindromic...

A prime palindrome integer is a positive integer (without leading zeros) which is prime as well as a palindrome. Given two positive integers M and N, where M < N, write a program to determine how many prime-palindrome integers are there in the range between M and N (both inclusive) and output them.

The input contains two positive integers M and N where M< 3000 and N<; 3000. Display the number of prime palindrome integers in the specified range along with their values in the format specified below:

Test your program with the sample data and some random data:
INPUT:                  M=100
N=1000
OUTPUT:               The prime palindrome integers are:
101, 131, 151, 181, 191, 313, 351, 373, 383, 727, 757, 787, 797, 919, 929
Frequency of prime palindrome integers: 15


INPUT:                  M=100
N=5000
OUTPUT:               Out of Range

Encryption

Encryption is the technique of coding message to maintain their secrecy. A string of size ‘n’ where n is greator than 1 and less than 10, stores single sentences (each sentence ends with a full Stop ) in each row of the array.
Write a program to accept the size of the array. Display an appropriate message if the size is not satisfying the given condition. Define a string array of the input size and fill it with sentence row-wise.
Change the sentence of the odd rows with an encryption of tho characters ahead of  the original characters. Also change the sentence of the even rows by sorting the sentence in reverse order/
Display the encrypt sentences as per the sample data given below:

Test your program with some sample data and some random data.

Input:          N=4
                             IT IS CLOUDY.
                             IT MAY RAIN.
                             THE WEATHER IS FINE.
                             IT IS COOL.
OUTPUT:
                             KV KU ENQWFA.
                             RAIN MAY IT.
                             VJG YGCV JGT KU HKPG.
                             COOL IS IT.


Merge Sort...

Write a program that inputs the names of people in to different arrays, A and B. Array A has N number of names while array B has M number of names, with no duplicates in either of them. Merge arrays A and B in to a single array C, such that the resulting array is stored alphabetically.
Display all the three arrays, A, B and C, stored alphabetically.
Test your program for the given data and some random data.

SAMPLE DATA
INPUT
Enter number of names in Array A, N = 2
Enter number of names in Array A, B = 2
First array:           (A)
Suman
Anil

Second array:                  (B)
Usha
Sachin
John

OUTPUT
Stored Merged array:       (C)
Anil
John
Sachin
Suman
Usha

Stored First array:           (A)
Anil
Suman

Stored second array:        (B)
John
Sachin

Usha

Smith Number...

A Smith number is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime factorization (excluding 1). The first few such numbers are 4, 22, 27, 58, 85, 94, 121 …..

Example :
1.    666
Prime factors are 2, 3, 3, and 37
Sum of the digits are (6+6+6)=18
Sum of digits of the factors (2+3+3+(3+7))=18

2.   4937775
Prime factors are 3, 5, 5, 65837
Sum of the digits are (4+9+3+7+7+7+5)=42
Sum of digits of the factors (3+5+5+(6+5+8+3+7))=42

Write a program to input a number and display whether the number is Smith number or not.
Sample data:
          Input 94               output                   Smith Number
          Input 102              output                   NOT Smith Number
          Input 666             output                   Smith Number

          Input 999              output                   NOT Smith Number

Base...

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 x 32 + 1 x 31 + 0 x 30), but in base 8 it is written as 14(1 x 81 + 4 x 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 x 31 + 2 x 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:
1 2 3 is not equal to 456 in any base between 2 to 20

INPUT:
X = 42, Y = 36
OUTPUT:

42 (base 7) = 36 (base 8)

Day for given date...

Write a program to accept a date in a specific string format (dd/mm/yyyy) and accept the name of the day on 1st January of the corresponding year. Find the day for the given date.
Example :
Input:          Enter the date ( in dd/mm/yyyy) format: 5/7/2001
Enter the Day on 1st January in this year: Monday

Output:                  5/7/2001 : Thursday

Test run the program on the following inputs.

Input date              Day on 1st  January                   Output day for Input date

4/941998              Thursday                        Friday
31/8/1998              Friday                                      Tuesday
6/12/2000             Saturday                        Wednesday

The program should include the part for validating the inputs namely the date and the day on 1st January of the year.

Anagrams...

we would like to generate all possible anagrams of a word. For example if the given word is ”TOP”, there will be 6 possible anagrams:
TOP,TPO,OTP,OPT,PTO,POT

An anagram must be printed only once you may output the anagram in any order. Also output the total number of anagrams. You may assume that the numbers of letters, N, in the word will be 7 at most, I.e., N<=7

Test your program for the given data and some random data.

Sample data:          Input:                    TO
                   Output:                  TO,OT
                   Total number of anagrams = 2

                   Input:          LEAN
                   Output:                  LEAN, LENA, LAEN, LANE, LNEA, LNAE, ELAN, ELNA,  EALN, EANL, ENLA, ENAL, ALEN, ALNE, AELN, AENL, ANLE, ANEL, NLEA, NLAE, NELA, NEAL, NALE, NAEL
Total number of anagrams= 24


Telephone...

A file contains a list of names and telephone numbers in the following form:-
AJIT                      281050
ANIL                     462890
RISHIKESH          524352

The names contains only one word and the names and telephone numbers are separated by white spaces. Write a interactive program to:-
·         Create the above file.
·         Display the content.
·         Search a telephone number for a given name( Assure No duplication  of name).
·         Exit the program.
The program must create the file for the first time.
Test your program for the following data:-
AJIT                      281050
ANIL                     462890
RISHIKESH           524352
JAVAGAL              345687
MONGIA                234561
RAHUL                  765433
ROBIN                             543221
SACHIN                 765433
SAURAV               8765908
VENKATESH                   7654322


Goldbach Number ISC 2018

Question: A Goldbach number is a positive even integer that can be expressed as the sum of two odd primes. Note: All even integer numbers ...