0% found this document useful (0 votes)
4 views7 pages

Practical Questions

The document contains a series of programming questions that require the implementation of algorithms to solve various mathematical and string-related problems. Each question specifies input constraints, expected outputs, and examples for testing. Topics include Fermat numbers, matrix operations, palindromes, Harshad numbers, pangrams, and ASCII-based encryption.

Uploaded by

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

Practical Questions

The document contains a series of programming questions that require the implementation of algorithms to solve various mathematical and string-related problems. Each question specifies input constraints, expected outputs, and examples for testing. Topics include Fermat numbers, matrix operations, palindromes, Harshad numbers, pangrams, and ASCII-based encryption.

Uploaded by

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

Practical Questions

Question 1
A Fermat number is a positive integer of the formFn = 22 n
+ 1, wherenis a non-negative integer. For example:

F0 = 3
F1 = 5
F 2 = 17
F 3 = 257

Write a program to accept an integerN where0 ≤ N ≤ 5. Compute and display the corresponding Fermat number
F N . IfN > 5, display an error message.

Test your program with the following data and some random data:
Example 1
INPUT:
N=2
OUTPUT:
Fermat Number F_2 = 17
Example 2
INPUT:
N=4
OUTPUT:
Fermat Number F_4 = 65537
Example 3
INPUT:
N=6
OUTPUT:
INVALID INPUT. NUMBER OUT OF RANGE.

Question 2
Write a program to declare a square matrixA[][]of orderN × N , whereN must be greater than 2 and less than 8.
Allow the user to input integers into this matrix. Perform the following tasks on the matrix:
1. Display the original matrix.
2. Rotate the matrix 90 degrees clockwise.
3. Display the rotated matrix.
Test your program for the following data and some random data:
Example 1
INPUT:
N=3
ENTER ELEMENTS OF MATRIX:
123
456
789
OUTPUT:
ORIGINAL MATRIX
123
456
789
ROTATED MATRIX
741
852
963
Example 2
INPUT:
N=4
ENTER ELEMENTS OF MATRIX:
1234
5678
9 10 11 12
13 14 15 16
OUTPUT:
ORIGINAL MATRIX
1234
5678
9 10 11 12
13 14 15 16
ROTATED MATRIX
13 9 5 1
14 10 6 2
15 11 7 3
16 12 8 4
Example 3
INPUT:
N=9
OUTPUT:
MATRIX SIZE OUT OF RANGE.

Question 3
A palindrome is a word, phrase, or sequence that reads the same backward as forward. Write a program to accept a
string and determine whether it is a palindrome or not. Ignore spaces, punctuation, and capitalization while
checking.
Test your program with the following data and some random data:
Example 1
INPUT:
String: "A man a plan a canal Panama"
OUTPUT:
The given string is a palindrome.
Example 2
INPUT:
String: "Hello World"
OUTPUT:
The given string is not a palindrome.
Example 3
INPUT:
String: "Madam In Eden, I'm Adam"
OUTPUT:
The given string is a palindrome.

Question 4
Write a program to find all pairs of integers(a, b)such that their product equals a given numberN , where
10 < N < 100. Bothaandbmust be positive integers.

Test your program with the following data and some random data:
Example 1
INPUT:
N = 24
OUTPUT:
PAIRS ARE:
(1, 24)
(2, 12)
(3, 8)
(4, 6)
Example 2
INPUT:
N = 45
OUTPUT:
PAIRS ARE:
(1, 45)
(3, 15)
(5, 9)
Example 3
INPUT:
N = 105
OUTPUT:
INVALID INPUT. NUMBER OUT OF RANGE.

Question 5
A Harshad Number (or Niven Number) is a number that is divisible by the sum of its digits. For example, 18 is a
Harshad number because:

Sum of digits = 1 + 8 = 9
18 is divisible by 9.
Write a program to accept an integer 'N' where 10 ≤ N ≤ 1000. Check whether the number is a Harshad number or
not. If it is a Harshad number, display "HARSHAD NUMBER"; otherwise, display "NOT A HARSHAD NUMBER".
Test your program with the following data and some random data:
Example 1
INPUT:
N = 18
OUTPUT:
HARSHAD NUMBER
Example 2
INPUT:
N = 19
OUTPUT:
NOT A HARSHAD NUMBER
Example 3
INPUT:
N = 100
OUTPUT:
HARSHAD NUMBER
Example 4
INPUT:
N=5
OUTPUT:
INVALID INPUT. NUMBER OUT OF RANGE.

Question 6
Write a program to declare a matrix a[][] of order (m × n) 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:
1. Display the original matrix.
2. Find and display the sum of the diagonal elements (left diagonal and right diagonal).
3. Display the matrix in a zig-zag order (first row left to right, second row right to left, and so on).
Test your program for the following data and some random data:
Example 1
INPUT:
M=3
N=3
ENTER ELEMENTS OF MATRIX:
123
456
789
OUTPUT:
ORIGINAL MATRIX:
123
456
789
SUM OF LEFT DIAGONAL: 15
SUM OF RIGHT DIAGONAL: 15
ZIG-ZAG ORDER:
123
654
789
Example 2
INPUT:
M=4
N=2
ENTER ELEMENTS OF MATRIX:
10 20
30 40
50 60
70 80
OUTPUT:
ORIGINAL MATRIX:
10 20
30 40
50 60
70 80
SUM OF LEFT DIAGONAL: 90
SUM OF RIGHT DIAGONAL: 90
ZIG-ZAG ORDER:
10 20
40 30
50 60
80 70
Example 3
INPUT:
M = 11
N=5
OUTPUT:
MATRIX SIZE OUT OF RANGE.

Question 7
A Pangram is a sentence that contains every letter of the alphabet at least once. For example, "The quick brown fox
jumps over the lazy dog" is a pangram. Write a program to accept a sentence (maximum 100 characters) and check
whether it is a pangram or not. If it is a pangram, display "PANGRAM"; otherwise, display "NOT A PANGRAM".
Note:
Ignore case sensitivity (treat uppercase and lowercase letters as the same).
The sentence may contain spaces, numbers, or special characters.
Test your program for the following data and some random data:
Example 1
INPUT:
Enter a sentence: The quick brown fox jumps over the lazy dog
OUTPUT:
PANGRAM
Example 2
INPUT:
Enter a sentence: Hello World
OUTPUT:
NOT A PANGRAM
Example 3
INPUT:
Enter a sentence: Pack my box with five dozen liquor jugs
OUTPUT:
PANGRAM

Question 8
Write a program to accept a word (in uppercase) and display its ASCII-based encryption. The encryption rule is as
follows:

Replace each character of the word with the next character in the ASCII table.
For 'Z', replace it with 'A'.
Test your program for the following data and some random data:
Example 1
INPUT:
WORD: HELLO
OUTPUT:
ENCRYPTED WORD: IFMMP
Example 2
INPUT:
WORD: ZEBRA
OUTPUT:
ENCRYPTED WORD: AFCSB
Example 3
INPUT:
WORD: 123
OUTPUT:
INVALID INPUT. WORD CONTAINS NON-ALPHABET CHARACTERS.

You might also like