Algorithm (2)
Algorithm (2)
Algorithm
Step 1: Start.
Step 2: Accept the value of n and create the array a [] of size n and b [] of
size n*n.
Step 3: Enter element in the array a [].
Step4: From i=0 to n-1 repeat step 5 to step 6.
Step 5: From j=i+1 to j<n repeat step 6.
Step 6: If a[j]>a [j+1] then interchange the element of a[j] with a [j+1].
Step 7: Execute a for loop from i=n -1, r=0 up to i=0.
Step 8: Execute an inner for loop for j=0 to j<=I and copy the element of
array a [] into b[r][j]=a[j].
Step 9: Print the filled matrix.
Step 10= Stop.
Program-27
Member function:
Matrev (int mm, int nn): parameterized constructor to initialize the data
member m=mm and n=nn.
Define the class MatRev giving details of the constructor(),void fillarray (),int
reverse (int),void revMat (MatRev)
And void shone().Define the main() fn to create objects and call the functions
accordingly.
Algorithm
Step 1: Start.
Step 2: Accept the number of row and column from the user and store it
to variable m and n respectively.
Step 3: Create the array arr [m] [n] and fill the array with integer values.
Step 4: Call the function RevMat() to reverse each element of the array .
Step 5: Call the function show() to display the array element in the matrix
format.
Step 6: Stop.
Program-28
Data member :
Member method :
Void fill() : fill the element in the array with first (m*n) composite number
column wise .
Algorithm
Step 1: Start.
Step 2: Accept the no of row and column from this and store it in
variable r and c respectively.
Step 3: Create object of class composite and all
all the function fill the matrix with composite numbers.
Step 4: Create for loop and the function isComposite to fill each cell of the
matrix with composite number.
Step 5: Display the matrix.
Step 6: Stop.
Program-29
Write a program to declare a matrix of order m*n where m is the number of row and n is the
number of column . Such that value m>0 and m<10 and n>2 and n<6.
Allow the user to input digit (0-7) only at each location such that each row represent an octal
number . Perform the following task :
Algorithm
Step 1: Start.
Step 2: Accept the size of row and column and store it in variable m and n
respectively.
Step 3: If m<=0 and m>=10 and n<=2 or n>=6, then print out of range and
exit the program.
Step 4: Create array a [] [] of size m*n.
Step 5: Accept the element in the array.
Step 6: Create for loop and calculate decimal equivalent of each row of
the entire matrix and display the result.
Step 7: Stop.
Program-30
Design a class EqMat to check if two matrices are equal or not .Assume that the two matrices
have the same dimension .Some of the member of the class are given below :
Data member :
Member function :
Void readarray():Enter element in the array int check (EqMat P, EqMat Q):
To check If the object P and Q are equal and return 0.
Algorithm
Step 1: Start.
Step 2: Accept the number of rows and column and store in variable m and n
respectively.
Step 3: Create two objects of class EqMat ob1 and ob2.
Step 4: Call the function read array() to accept element in the array.
Step 5: Call the function check passing two object ob1 and ob2 and store the return
result in variable p.
Step 6: If p=1 then display matrices are equal else display matrices are not equal.
Step 7: Display both the matrices.
Step 8: Stop.
Program-31
Algorithm
Step 1: Start.
Step 2: Accept the number of rows and columns and store it in variable m and n
respectively.
Step 3: Create the array mat[m] [n] and enter element in the array.
Step 4: Call the function Cyclic() by passing object to shuffle the row of the matrix.
Step 5: Display the array after shuffling.
Step 6: Stop.
Program-32
Data member :
Member function :
Void check() : check whether the number and display the result with a appropriate message.
Algorithm
Step 1: Start.
Step 2: Accept a number and store it in variable a.
Step 3: Create object of the class and initialize data member of the class.
Step 4: Call the function CountDigit() to count total number of digit in the number and
store it to variable size.
Step 5: Call the function SumofDigit() to return the sum of digit to the power of their
respective position.
Step 6: Check whether the return value from the function SumofDigit() is equal to the
input number the display ‘disarium number’ other wise display ‘not disarium number’.
Step 7: Stop.
Program-33
A class palin has been defined to check whether a positive number is a palindrome number or
not.
The number ‘N’ is a palindrome if the original number and its reverse are same .
Data member :
Methods :
Void check():checks weather the number is palindrome or not by invoiking the function
reverse()and display the result with an appropriate message
Algorithm
Step 1: Start.
Step 2: Accept a number and store it in num.
Step 3: Call the function reverse passing the num as argument. The function will return
the reverse of the past value.
Step 4: Call function check() to check whether the reverse number and original
number are same then display the message “palindrome number”.
Step 5: Stop.
Program-34
Member function
Double findpower(intx,int y):to return x raise to the power of y using recursive technique
Void calculate():to calculate the sum of series by invoking the recursive functions
Algorithm
Step 1: Start.
Step 2: Accept the value of x and n.
Step 3: Call the function calculate() to calculate the sum of given series by invoking the
function findfact() and findpower().
Step 4: Call the function display() to display the sum of the series.
Step 5: Stop.
Program 35
Write a class program to perform the matrix operations as per the specifications shown
below
Class :matrixop
Data members
Void get():to store sum of squares of row number and coloumn number in each of the matrix
Void cal():to print the sum of the prime numbers available on the left diagonal as well as sum
of the elements except boundary elements.
Define the main () functions ro make use of all other functions shown above.
Algorithm
Step 1 : Start
Step 2 : Create an array arr[20][20].
Step 3 :Call the function get () to store the sum of square of row number and column
number in each of the corresponding call of the array.
Step 4 : Call the function low() to display the element of the array.
Step 5 : call the function cal () to display the sum of prime number on the left diagonal
as well as sum of elements except boundary elements.
Step 6 : Stop.