Previous Year Written Question(old)
#include <iostream>
using namespace std;
int main() {
int size1, size2;
// Taking input size of first array
cout << "Enter size of first array: ";
cin >> size1;
int arr1[size1];
cout << "Enter elements of first array:\n";
for (int i = 0; i < size1; i++) {
cin >> arr1[i];
}
// Taking input size of second array
cout << "Enter size of second array: ";
cin >> size2;
int arr2[size2];
cout << "Enter elements of second array:\n";
for (int i = 0; i < size2; i++) {
cin >> arr2[i];
}
// To store common elements
int commonElements[size1 < size2 ? size1 : size2];
int count = 0;
// Check each element in arr1 against arr2
for (int i = 0; i < size1; i++) {
bool found = false;
for (int j = 0; j < size2; j++) {
if (arr1[i] == arr2[j]) {
found = true;
break;
}
}
if (found) {
// Check for duplicates
bool alreadyExists = false;
for (int k = 0; k < count; k++) {
if (commonElements[k] == arr1[i]) {
alreadyExists = true;
break;
}
}
if (!alreadyExists) {
commonElements[count] = arr1[i];
count++;
}
}
}
// Print common elements
cout << "Common elements: ";
for (int i = 0; i < count; i++) {
cout << commonElements[i] << " ";
}
cout << endl;
// Print total count
cout << "Total number of common elements: " << count << endl;
return 0;
}
Sample I/O:
Enter size of first array: 5
Enter elements of first array: 0 20 30 40 50
Enter size of second array: 6
Enter elements of second array: 10 2 20 30 60 90
Common elements: 20 30
Total number of common elements: 2
=== Code Execution Successful ===#include <stdio.h> /* Function to calculate sum of even numbers from 1 to n */ int sumOfEven(int n) { int sum = 0; for (int i = 2; i <= n; i += 2) { sum += i; } return sum; } int main() { int n, result; printf("Enter an integer: "); scanf("%d", &n); result = sumOfEven(n); printf("Sum of even numbers from 1 to %d = %d\n", n, result); return 0; }
Sample I/O:
Enter an integer: 50
Sum of even numbers from 1 to 50 = 650
=== Code Execution Successful ===
#include <stdio.h>
void printDivisibleBy3(int arr[], int size) {
for (int i = 0; i < size; i++) {
if (arr[i] % 3 == 0) {
printf("%d\n", arr[i]);
}
}
}
int main() {
int size;
printf("Enter the number of elements: ");
scanf("%d", &size);
int numbers[size]; // Variable Length Array (VLA)
printf("Enter %d numbers:\n", size);
for (int i = 0; i < size; i++) {
scanf("%d", &numbers[i]);
}
printf("Numbers divisible by 3:\n");
printDivisibleBy3(numbers, size);
return 0;
}Sample I/O:
Enter the number of elements: 6
Enter 6 numbers:
5 6 9 12 8 11
Numbers divisible by 3:
6
9
12
=== Code Execution Successful ===. A class BankAccount with data members for account holder's name, account number, and balance.
. Member functions to deposit() money, withdraw() money (ensuring sufficient balance), and display() account details.
Demonstrate the concept of encapsulation by keeping data member's private and providing appropriate public methods for accessing and modifying them. CB, SO (it), 2025
#include <iostream> using namespace std; class BankAccount { private: string name; int accountNumber; double balance; public: void setDetails(string n, int accNo, double bal) { name = n; accountNumber = accNo; balance = bal; } void deposit(double amount) { balance += amount; cout << "Deposited: " << amount << endl; } void withdraw(double amount) { if (amount <= balance) { balance -= amount; cout << "Withdrawn: " << amount << endl; } else { cout << "Insufficient balance" << endl; } } void display() { cout << "\nAccount Details\n"; cout << "Account Holder: " << name << endl; cout << "Account Number: " << accountNumber << endl; cout << "Balance: " << balance << endl; } }; int main() { BankAccount acc; string name; int accNo; double bal, dep, wit; cout << "Enter account holder name: "; getline(cin, name); cout << "Enter account number: "; cin >> accNo; cout << "Enter initial balance: "; cin >> bal; acc.setDetails(name, accNo, bal); cout << "Enter amount to deposit: "; cin >> dep; acc.deposit(dep); cout << "Enter amount to withdraw: "; cin >> wit; acc.withdraw(wit); acc.display(); return 0; }
Sample I/O:
Enter account holder name: itjobqns
Enter account number: 02252016
Enter initial balance: 5000
Enter amount to deposit: 300
Deposited: 300
Enter amount to withdraw: 100
Withdrawn: 100
Account Details
Account Holder: itjobqns
Account Number: 2252016
Balance: 5200
=== Code Execution Successful ===
#include <stdio.h>
// Function to find the missing number
int findMissing(int arr[], int size) {
int total = (size * (size + 1)) / 2; // Sum of numbers from 1 to size
int sum = 0;
for(int i = 0; i < size; i++) {
sum += arr[i];
}
return total - sum; // Missing number
}
int main() {
int arr[10] = {1, 2, 3, 4, 5, 0, 7, 8, 9, 10};
int missing;
missing = findMissing(arr, 10);
// Replace zero with missing number
for(int i = 0; i < 10; i++) {
if(arr[i] == 0) {
arr[i] = missing;
}
}
printf("Restored Array:\n");
for(int i = 0; i < 10; i++) {
printf("%d ", arr[i]);
}
return 0;
}
Sample input:
Enter value of n: 20
Sample Output:
Prime Numbers: 2, 3, 5, 7, 11, 13, 17, 19Combined Bank (SO(it)), 2024
#include <iostream>
using namespace std;
bool isPrime(int num) {
if (num < 2) return false;
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) return false;
}
return true;
}
void findPrimes(int n) {
cout << "Prime Numbers: ";
for (int i = 1; i <= n; i++) {
if (isPrime(i))
cout << i << " ";
}
cout << endl;
}
int main() {
int n;
cout << "Enter value of n: ";
cin >> n;
findPrimes(n);
return 0;
}
Sample I/O:Enter value of n: 20
Prime Numbers: 2 3 5 7 11 13 17 19
Combined Bank (SO(it)), 2024 #include <stdio.h>
int main() {
int m, n, i, j;
// Input matrix dimensions
printf("Enter the number of rows (m): ");
scanf("%d", &m);
printf("Enter the number of columns (n): ");
scanf("%d", &n);
int matrix[m][n];
// Input matrix elements
printf("Enter the elements of the matrix row-wise:\n");
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &matrix[i][j]);
}
}
// Calculate and print row sums
printf("\nMatrix with Row Sums:\n");
for (i = 0; i < m; i++) {
int rowSum = 0;
for (j = 0; j < n; j++) {
printf("%d ", matrix[i][j]);
rowSum += matrix[i][j];
}
printf("%d\n", rowSum); // Row sum
}
// Calculate and print column sums
printf("\nColumn Sums:\n");
for (j = 0; j < n; j++) {
int colSum = 0;
for (i = 0; i < m; i++) {
colSum += matrix[i][j];
}
printf("%d ", colSum);
}
return 0;
}
Sample I/O:Enter the number of rows (m): 3 Enter the number of columns (n): 4 Enter the elements of the matrix row-wise: 1 3 4 2 2 4 5 3 3 2 2 5 Output: Matrix with Row Sums: 1 3 4 2 10 2 4 5 3 14 3 2 2 5 12 Column Sums: 6 9 11 10
#include <iostream>
using namespace std;
int main() {
int i, num, n, count;
cout << "Enter the range: ";
cin >> n;
cout << "The prime numbers in between the range 1 to " << n << " are: ";
for (num = 1; num <= n; num++) {
count = 0;
for (i = 2; i <= num / 2; i++) {
if (num % i == 0) {
count++;
break;
}
}
if (count == 0 && num != 1)
cout << num << " ";
}
return 0;
}Sample I/O:
Enter the range: 50
The prime numbers in between the range 1 to 50 are: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
=== Code Execution Successful ===Expected Output:
1
01
101
0101
10101
#include <iostream>
using namespace std;
int main() {
int i, j, n, p, q;
cout << "Input number of rows: ";
cin >> n;
for (i = 1; i <= n; i++) {
if (i % 2 == 0) {
p = 1;
q = 0;
} else {
p = 0;
q = 1;
}
for (j = 1; j <= i; j++) {
if (j % 2 == 0)
cout << p;
else
cout << q;
}
cout << endl;
}
return 0;
}Sample I/O:
Input number of rows: 6
1
01
101
0101
10101
010101
=== Code Execution Successful ===#include <iostream>
using namespace std;
int main() {
int n, i, sum = 0, term = 1, nextTerm;
cout << "Enter the value of n: ";
cin >> n;
cout << "The series is: ";
for (i = 1; i <= n; i++) {
cout << term << " ";
sum += term;
nextTerm = term + i;
term = nextTerm;
}
cout << "\nThe sum of the series is: " << sum << endl;
return 0;
}Sample I/O:
Enter the value of n: 10
The series is: 1 2 4 7 11 16 22 29 37 46
The sum of the series is: 175
=== Code Execution Successful ===#include <stdio.h>
int main() {
int n, i;
int a = 0, b = 1, next;
printf("Enter number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series:\n");
for(i = 1; i <= n; i++) {
printf("%d ", a);
next = a + b;
a = b;
b = next;
}
return 0;
}
Input: 5 Output: Fibonacci Series: 0 1 1 2 3
#include <stdio.h>
int main() {
int n, i, pos[100], neg[100];
int p = 0, ne = 0;
printf("Enter number of elements: ");
scanf("%d", &n);
int arr[100];
printf("Enter elements:\n");
for(i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
// Separate positive and negative numbers
for(i = 0; i < n; i++) {
if(arr[i] >= 0)
pos[p++] = arr[i];
else
neg[ne++] = arr[i];
}
// Rearrange: positives first, then negatives
printf("Rearranged array:\n");
for(i = 0; i < p; i++) {
printf("%d ", pos[i]);
}
for(i = 0; i < ne; i++) {
printf("%d ", neg[i]);
}
return 0;
}
Input: 5 1 -2 3 -4 5 Output: Rearranged array: 1 3 5 -2 -4
#include <stdio.h>
int isLeapYear(int year) {
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
return 1;
return 0;
}
int main() {
int day, month, year;
int valid = 1;
printf("Enter day month year: ");
scanf("%d %d %d", &day, &month, &year);
// Check month validity
if (month < 1 || month > 12)
valid = 0;
// Days in months
int daysInMonth[] = {31,28,31,30,31,30,31,31,30,31,30,31};
// Adjust February for leap year
if (isLeapYear(year))
daysInMonth[1] = 29;
// Check day validity
if (day < 1 || day > daysInMonth[month - 1])
valid = 0;
if (valid)
printf("Valid Date\n");
else
printf("Invalid Date\n");
return 0;
}
A year is considered a leap year if:
• It is divisible by 4 but not divisible by 100, OR
• It is divisible by 400
In the program, February (month = 2) is assigned 29 days instead of 28 when the year is a leap year.
#include <stdio.h>
int main() {
int num, i, isPrime = 1;
printf("Enter a number: ");
scanf("%d", &num);
if (num <= 1) {
isPrime = 0;
} else {
for (i = 2; i <= num / 2; i++) {
if (num % i == 0) {
isPrime = 0;
break;
}
}
}
if (isPrime)
printf("%d is a prime number.\n", num);
else
printf("%d is not a prime number.\n", num);
return 0;
}
int a = 5, b= 18, c = 27,
a=b++ + ++c;
b = a++ - c --;
c= a++ + b --;
C++ Code Execution Explanation
Step-by-Step Execution
Initial values:
a = 5, b = 18, c = 27
Step 1: a = b++ + ++c;
• b++ → use 18, then b = 19
• ++c → increment first → c = 28, use 28
⇒ a = 18 + 28 = 46
Now: a = 46, b = 19, c = 28
Step 2: b = a++ - c--;
• a++ → use 46, then a = 47
• c-- → use 28, then c = 27
⇒ b = 46 – 28 = 18
Now: a = 47, b = 18, c = 27
Step 3: c = a++ + b--;
• a++ → use 47, then a = 48
• b-- → use 18, then b = 17
⇒ c = 47 + 18 = 65
Now: a = 48, b = 17, c = 65
Final Output
a = 48 b = 17 c = 65
#include <stdio.h> int main() { int num, sum = 0, digit; printf("Enter a 5-digit number: "); scanf("%d", &num); while (num != 0) { digit = num % 10; // get last digit sum = sum + digit; // add digit to sum num = num / 10;// remove last digit } printf("Sum of digits = %d\n", sum); return 0; }
#include <stdio.h>
// Recursive function to find nth Fibonacci number
int fibonacci(int n) {
if (n == 0)
return 0;
else if (n == 1)
return 1;
else
return fibonacci(n - 1) + fibonacci(n - 2);
}
int main() {
int n;
printf("Enter value of n: ");
scanf("%d", &n);
printf("The %dth Fibonacci number is: %d\n", n, fibonacci(n));
return 0;
}
#include <stdio.h>
int main() {
int n, i;
float x, sum = 1, term = 1;
printf("Enter value of x: ");
scanf("%f", &x);
printf("Enter number of terms: ");
scanf("%d", &n);
// Calculate series
for (i = 1; i <= n; i++) {
term = term * x / i; // x^i / i!
sum = sum + term;
}
printf("Value of e^x = %.4f\n", sum);
return 0;
}
1, 2, 2, 3, 3, 3, ……………………..100 (100times )Sonali and Janata Bank, O(it), 2023
#include <iostream>
using namespace std;
int main() {
// Loop from 1 to 100
for (int n = 1; n <= 100; n++) {
// Inner loop to repeat 'n' exactly 'n' times
for (int i = 0; i < n; i++) {
cout << n << " ";
}
}
cout << endl; // Print a newline at the end of the sequence
return 0;
}
int F(n) {
if n == 0
return 0;
if n == 1
return 1;
return F(n-2)+F(n-1);
}
int main () {
result F(5);
}
The output of the program will be 5.
=====================
Code Analysis
- Function
F(n):- The function calculates the Fibonacci number for a given
nusing recursion. - Base Cases:
- If
n == 0, it returns 0. - If
n == 1, it returns 1.
- If
- Recursive Case:
- For other values of
n, it returnsF(n-2) + F(n-1).
- For other values of
- The function calculates the Fibonacci number for a given
- Main Function:
- The main function calls
F(5)and stores the result (though it should be assigned to a variable likeresult).
- The main function calls
Calculation of F(5)
The Fibonacci sequence calculated by the function is:
F(4) = F(3) + F(2)
F(3) = F(2) + F(1)
F(2) = F(1) + F(0)
Breaking it down:
F(2) = 1 (F(1) + F(0) = 1 + 0)
F(3) = 2 (F(2) + F(1) = 1 + 1)
F(4) = 3 (F(3) + F(2) = 2 + 1)
F(5) = 5 (F(4) + F(3) = 3 + 2)
A) Find matrices C that is multiplication A and B.
B) Find average in A and B.
C) Max from matrices C CB, SO(it), 2023
#include <iostream>
using namespace std;
void matrix_multiply(int A[10][10], int B[10][10], int C[10][10], int m, int n, int p, int q) {
if (n != p) {
cout << "Matrices A and B cannot be multiplied due to incompatible dimensions.\n";
return;
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < q; j++) {
C[i][j] = 0;
for (int k = 0; k < n; k++) {
C[i][j] += A[i][k] * B[k][j];
}
}
}
}
float calculate_average(int matrix[10][10], int m, int n) {
int sum = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
sum += matrix[i][j];
}
}
return static_cast(sum) / (m * n);
}
int find_max(int matrix[10][10], int m, int n) {
int max = matrix[0][0];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) { if (matrix[i][j] > max) {
max = matrix[i][j];
}
}
}
return max;
}
int main() {
int A[10][10], B[10][10], C[10][10];
int m, n, p, q;
cout << "Enter the number of rows and columns for matrix A (m x n): "; cin >> m >> n;
cout << "Enter the number of rows and columns for matrix B (p x q): "; cin >> p >> q;
if (n != p) {
cout << "Matrices A and B cannot be multiplied due to incompatible dimensions.\n";
return 0;
}
// Input matrices A and B
cout << "Enter elements of matrix A:\n";
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) { cin >> A[i][j];
}
}
cout << "Enter elements of matrix B:\n";
for (int i = 0; i < p; i++) {
for (int j = 0; j < q; j++) { cin >> B[i][j];
}
}
// A) Multiply matrices A and B
matrix_multiply(A, B, C, m, n, p, q);
cout << "Matrix C (A x B):\n";
for (int i = 0; i < m; i++) {
for (int j = 0; j < q; j++) {
cout << C[i][j] << " ";
}
cout << endl;
}
// B) Calculate the average of matrices A and B
float average_A = calculate_average(A, m, n);
float average_B = calculate_average(B, p, q);
cout << "Average of Matrix A: " << average_A << endl;
cout << "Average of Matrix B: " << average_B << endl;
// C) Find the maximum value in matrix C
int max_C = find_max(C, m, q);
cout << "Maximum value in Matrix C: " << max_C << endl;
return 0;
}
Sample I/O:
Enter the number of rows and columns for matrix A (m x n): 3 3
Enter the number of rows and columns for matrix B (p x q): 3 3
Enter elements of matrix A:
1 5 7 6 3 2 69 7 12
Enter elements of matrix B:
45 63 2 9 8 7 12 10 3
Matrix C (A x B):
174 173 58
321 422 39
3312 4523 223
Average of Matrix A: 12.4444
Average of Matrix B: 17.6667
Maximum value in Matrix C: 4523
=== Code Execution Successful ===
🔗 Run Online: Matrix Calculation
#include <iostream>
int main() {
int n;
std::cout << "Enter the number of terms for the fibonacci series: ";
std::cin >> n;
int first = 0, second = 1;
if (n > 1) {
std::cout << "Fibonacci Series: " << first;
if (n > 2) {
std::cout << ", " << second;
}
for (int i = 2; i < n; i++) {
int next = first + second;
std::cout << ", " << next;
first = second;
second = next;
}
}
std::cout << std::endl;
return 0;
}Rupali, ANE, 2023
Program Output (Assume input n = 6)
The program prints the Fibonacci series up to n terms.
Input: Enter the number of terms for the fibonacci series: 6
Output: Fibonacci Series: 0, 1, 1, 2, 3, 5
Explanation of the Program:
The program first takes an integer n as input. It initializes the first two Fibonacci numbers as 0 and 1.
If n is greater than 1, it prints the first number (0). If n is greater than 2, it prints the second number (1).
Then a loop runs from i = 2 to i < n, where each next Fibonacci number is calculated by adding the previous two numbers and printed.
Time Complexity:
The loop runs (n − 2) times, so the time complexity is O(n).
Space Complexity:
The program uses a constant number of variables, so the space complexity is O(1).
Program Output (ধরা যাক input n = 6)
এই program টি Fibonacci series-এর n টি term print করে।
Input: Enter the number of terms for the fibonacci series: 6
Output: Fibonacci Series: 0, 1, 1, 2, 3, 5
Program-এর ব্যাখ্যা:
Program টি প্রথমে একটি integer n ইনপুট নেয়। এরপর Fibonacci series-এর প্রথম দুটি সংখ্যা 0 ও 1 initialize করে।
যদি n > 1 হয়, তাহলে প্রথম সংখ্যা 0 print করে। যদি n > 2 হয়, তাহলে দ্বিতীয় সংখ্যা 1 print করে।
এরপর একটি loop i = 2 থেকে i < n পর্যন্ত চলে, যেখানে আগের দুইটি সংখ্যার যোগফল নিয়ে পরবর্তী Fibonacci সংখ্যা বের করে print করা হয়।
Time Complexity:
Loop টি (n − 2) বার চলে, তাই program-এর time complexity হলো O(n)।
Space Complexity:
Program টি নির্দিষ্ট কয়েকটি variable ব্যবহার করে, তাই space complexity হলো O(1)।
Algorithm to Find the Smallest Element in an Array
START
Step 1 → Initialize an array A with given values.
Step 2 → Create a variable min_value and set it to a large number (e.g., infinity) or the first element of the array.
Step 3 → Loop through each element A[i] in the array starting from the first element.
Step 4 → For each element, check if A[i] is smaller than min_value.
Step 5 → If A[i] < min_value, update min_value to A[i].
Step 6 → Repeat Steps 4 and 5 until all elements have been checked.
Step 7 → Display min_value as the smallest element of the array.
STOP
#include <stdio.h>
int findSmallest(int arr[], int size) {
// 1. Assume the first number is the smallest
int smallest = arr[0];
// 2. Look at the rest of the numbers one by one
for (int i = 1; i < size; ++i) {
// 3. If we find a number that is smaller, save it
if (arr[i] < smallest) {
smallest = arr[i];
}
}
// 4. Send back the smallest number we found
return smallest;
}#include <stdio.h> int main () { int n1, n2, max; printf ("Enter two positive integers: "); scanf ("%d %d", &n1, &n2); // maximum number between n1 and n2 is stored in max max = (n1> n2) ? n1: n2; while (1) { // Check if max is divisible by both n1 and n2 if ((max% n1 == 0)&& (max % n2 ==0)) { // If true, max is the LCM of n1 and n2 printf("The LCM of %d and %d is %d.", n1,n2,max); break; } ++max; } return 0; }
Sample I/O:
Enter two positive integers: 14 8
The LCM of 14 and 8 is 56.
=== Code Execution Successful ===
Previous Year Written Question
- 1Programming ConceptWrite a recursive function that returns a boolean after taking a string as parameter to check if its a palindrome or not.CB, SO(IT), 22 | Senior Officer (IT)
#include<stdio.h> using namespace std; // Recursive function to check if a string is a palindrome bool isPalindrome(string str, int start, int end) { // Base case: If the start index is greater than or equal to the end index if (start >= end) { return true; } // Check if the first and last characters are the same if (str[start] != str[end]) { return false; } // Recursive case: Check the substring excluding the first and last characters return isPalindrome(str, start + 1, end - 1); } int main() { string input; cout << "Enter a string: "; cin >> input; if (isPalindrome(input, 0, input.length() - 1)) { cout << input << " is a palindrome." << endl; } else { cout << input << " is not a palindrome." << endl; } return 0; }Sample I/O:
Enter a string: noon
noon is a palindrome.
=== Code Execution Successful ===🔗 Run Online: Check Palindrome
- 2Programming ConceptWrite pseudocode or code in any programming language where every character of a string increases by 1 alphabetically, such as a -> b and z -> a.ICB, AP, 26 | Others
The problem requires character-wise transformation of a string where each alphabet is shifted by one position in the alphabet. This is commonly known as a Caesar cipher with shift 1.
Logic:
Each character is checked individually. If it is 'z', it wraps to 'a'. If it is 'Z', it wraps to 'A'. Otherwise, ASCII value is incremented by 1.
Pseudocode:
FUNCTION shiftString(S)
RESULT = "
FOR EACH character c IN S
IF c == 'z' THEN
RESULT = RESULT + 'a'
ELSE IF c == 'Z' THEN
RESULT = RESULT + 'A'
ELSE
RESULT = RESULT + (c + 1)
END IF
END FOR
RETURN RESULT
END FUNCTIONConclusion: This algorithm runs in O(n) time complexity where n is the length of the string.
Pseudocode Solution
FUNCTION shiftString(S)
RESULT = "
FOR EACH CHAR c IN S
IF c == 'z' THEN
RESULT = RESULT + 'a'
ELSE IF c == 'Z' THEN
RESULT = RESULT + 'A'
ELSE
RESULT = RESULT + (c + 1)
END IF
END FOR
RETURN RESULT
END FUNCTIONপ্রতিটি character কে ASCII অনুযায়ী +1 shift করা হয় এবং z/Z হলে wrap করে a/A তে নেয়া হয়।
- 3Programming ConceptWrite a java code which returns a valueIslami, QA(Engineer), 25 | Bank
public class Calculator { public static int add(int a, int b) { return a + b; } public static void main(String[] args) { int result = add(10, 20); System.out.println("The sum is: " + result); } }add() নামের একটা মেথড তৈরি করা হয়েছে যেটা দুইটা সংখ্যা (a এবং b) ইনপুট হিসেবে নিয়েmain() মেথডে- মেথড যোগফল হিসাব করে ৩০ রিটার্ন করেছে, যেটা
resultভ্যারিয়েবলে সংরক্ষণ করা হয়েছে। শেষে
System.out.println()দিয়ে “The sum is: 30” প্রিন্ট করা হয়েছে।
- মেথড যোগফল হিসাব করে ৩০ রিটার্ন করেছে, যেটা
- 4Programming ConceptWrite JAVA CodeIslami, QA(Engineer), 25 | Banknot collected
- 5Programming ConceptWrite a C/C++ program to check Balanced parentheses in an Expression.6 Bank & FI, AP, 21 | Bank
#include <bits/stdc++.h> using namespace std; // function to check if brackets are balanced bool areBracketsBalanced(string expr) { stack s; char x; // Traversing the Expression for (int i = 0; i < expr.length(); i++) { if (expr[i] == '(' || expr[i] == '[' || expr[i] == '{') { // Push the element in the stack s.push(expr[i]); continue; } // IF current current character is not opening // bracket, then it must be closing. So stack // cannot be empty at this point. if (s.empty()) return false; switch (expr[i]) { case ')': // Store the top element in a x = s.top(); s.pop(); if (x == '{' || x == '[') return false; break; case '}': // Store the top element in b x = s.top(); s.pop(); if (x == '(' || x == '[') return false; break; case ']': // Store the top element in c x = s.top(); s.pop(); if (x == '(' || x == '{') return false; break; } } // Check Empty Stack return (s.empty()); } // Driver code int main() { string expr; // Taking input from the user cout << "Enter an expression: "; cin >> expr; // Function call if (areBracketsBalanced(expr)) cout << "Balanced\n"; else cout << "Not Balanced\n"; return 0; }
Source : GeeksforGeeks
- 6Programming ConceptWe are given an array of integers and a range, we need to find whether the subarray which falls in this range has values in the form of a mountain or not. All values of the subarray are said to be in the form of a mountain if either all values are increasing or decreasing or first increasing and then decreasing. Write a C/C++ Program that shows input is a Mountain sequence or Not Mountain sequence.6 Bank & FI, AP, 21 | Bank
#include <bits/stdc++.h> using namespace std; #define ll long long bool isMountain(vector<ll> a) { ll n = a.size(); if (n < 3) return false; ll i = 1; // Increasing part while (i < n && a[i] > a[i - 1]) { i++; } // Peak cannot be first or last if (i == 1 || i == n) return false; // Decreasing part while (i < n && a[i] < a[i - 1]) { i++; } return i == n; } int main() { ll n; cin >> n; vector<ll> a(n); for (ll i = 0; i < n; i++) { cin >> a[i]; } if (isMountain(a)) { cout << "Mountain" << endl; } else { cout << "Not Mountain" << endl; } return 0; }
Source: Geeksforgeeks
- 7Programming ConceptGiven n jobs starting time n[] and duration d[], print maximum number of jobs that don't overlap between each other.6 Bank & FI, AP, 21 | Bank
#include <bits/stdc++.h> using namespace std; #define N 6 // Define structure for Activity struct Activity { int start, finish; }; // Function to compare two activities bool Sort_activity(Activity s1, Activity s2) { return (s1.finish < s2.finish); // Sort by finish time } // Function to print the maximum number of activities void print_Max_Activities(Activity arr[], int n) { // Sort activities based on finish time sort(arr, arr + n, Sort_activity); cout << "Following activities are selected: \n"; int i = 0; cout << "(" << arr[i].start << ", " << arr[i].finish << ")\n"; // Select the next activity that starts after the last selected activity finishes for (int j = 1; j < n; j++) { if (arr[j].start >= arr[i].finish) { cout << "(" << arr[j].start << ", " << arr[j].finish << ")\n"; i = j; } } } int main() { Activity arr[N]; // Taking input from the user for (int i = 0; i < N; i++) { cout << "Enter the start and finish time for job " << i + 1 << " : "; cin >> arr[i].start >> arr[i].finish; } // Function call to print the selected activities print_Max_Activities(arr, N); return 0; }
Code Link
- 8Programming ConceptWrite a C/C++ Program that has a Class Account, Subclass Savings Account, Current Account etc with related hierarchy way.6 Bank & FI, AP, 21 | Bank
Code Link#include <iostream> #include <string> using namespace std; // Bank Management System using Class & Inheritance in C++ /* 1. Saving Account 2. Current Account 3. Account Creation 4. Deposit 5. Withdraw 6. Balance */ class account { private: string name; int accno; string atype; public: void getAccountDetails() { cout << "\nEnter Customer Name : "; cin >> name; cout << "Enter Account Number : "; cin >> accno; cout << "Enter Account Type : "; cin >> atype; } void displayDetails() { cout << "\n\nCustomer Name : " << name; cout << "\nAccount Number : " << accno; cout << "\nAccount Type : " << atype; } }; class current_account : public account { private: float balance = 0; public: void c_display() { cout << "\nBalance : " << balance; } void c_deposit() { float deposit; cout << "\nEnter amount to Deposit : "; cin >> deposit; balance = balance + deposit; } void c_withdraw() { float withdraw; cout << "\n\nBalance : " << balance; cout << "\nEnter amount to be withdraw : "; cin >> withdraw; if (balance >= withdraw && balance > 1000) { balance = balance - withdraw; cout << "\nBalance Amount After Withdraw: " << balance; } else { cout << "\nInsufficient Balance"; } } }; class saving_account : public account { private: float sav_balance = 0; public: void s_display() { cout << "\nBalance : " << sav_balance; } void s_deposit() { float deposit, interest; cout << "\nEnter amount to Deposit : "; cin >> deposit; sav_balance = sav_balance + deposit; interest = (sav_balance * 2) / 100; sav_balance = sav_balance + interest; } void s_withdraw() { float withdraw; cout << "\nBalance : " << sav_balance; cout << "\nEnter amount to be withdraw : "; cin >> withdraw; if (sav_balance >= withdraw && sav_balance > 500) { sav_balance = sav_balance - withdraw; cout << "\nBalance Amount After Withdraw: " << sav_balance; } else { cout << "\nInsufficient Balance"; } } }; int main() { current_account c1; saving_account s1; char type; int choice; cout << "\nEnter S for saving customer and C for current a/c customer : "; cin >> type; if (type == 's' || type == 'S') { s1.getAccountDetails(); while (1) { cout << "\nChoose Your Choice" << endl; cout << "1) Deposit" << endl; cout << "2) Withdraw" << endl; cout << "3) Display Balance" << endl; cout << "4) Display with full Details" << endl; cout << "5) Exit" << endl; cout << "Enter Your choice: "; cin >> choice; switch (choice) { case 1: s1.s_deposit(); break; case 2: s1.s_withdraw(); break; case 3: s1.s_display(); break; case 4: s1.displayDetails(); s1.s_display(); break; case 5: goto end; default: cout << "\n\nEntered choice is invalid, TRY AGAIN"; } } } else if (type == 'c' || type == 'C') { c1.getAccountDetails(); while (1) { cout << "\nChoose Your Choice" << endl; cout << "1) Deposit" << endl; cout << "2) Withdraw" << endl; cout << "3) Display Balance" << endl; cout << "4) Display with full Details" << endl; cout << "5) Exit" << endl; cout << "Enter Your choice: "; cin >> choice; switch (choice) { case 1: c1.c_deposit(); break; case 2: c1.c_withdraw(); break; case 3: c1.c_display(); break; case 4: c1.displayDetails(); c1.c_display(); break; case 5: goto end; default: cout << "\n\nEntered choice is invalid, TRY AGAIN"; } } } else { cout << "\nInvalid Account Selection"; } end: cout << "\nThank You for Banking with us.."; return 0; } - 9Programming ConceptAnswer the following question from the below code:
int fibo (int x, int y)
{
int A = 0; if (x>0&& y<20 {
A = 1 ; }
if ( x = = 10) {
return A; }
return 0;
}
(i) Draw the flowchart based on above code
(ii) How many conditions are in this code?
(iii) Finding the possible path.Pubali, SQA, 23 |(i) Answer:
(ii) Answer: There are two conditions in the code:
(a) The first condition is x> 0 && y <20
(b) The second condition is x=10
(iii) Answer:
(iii) Finding the possible path. There are two possible paths through the code: (a) If x>0&&y<20 is true and x is not equal to 10, the function returns 0.
(b) If x> 0 && y 0 && y < 20 is false, the function also returns 0.
- 10Programming ConceptWrite a structured program (in C or Python) that takes an integer input n and prints the sum of all even numbers from 1 to n.Combined Bank, SO-IT, 25 | Senior Officer (IT)
#include <stdio.h> /* Function to calculate sum of even numbers from 1 to n */ int sumOfEven(int n) { int sum = 0; for (int i = 2; i <= n; i += 2) { sum += i; } return sum; } int main() { int n, result; printf("Enter an integer: "); scanf("%d", &n); result = sumOfEven(n); printf("Sum of even numbers from 1 to %d = %d\n", n, result); return 0; }
Sample I/O: Enter an integer: 50 Sum of even numbers from 1 to 50 = 650 === Code Execution Successful ===🔗 Run Online: Sum of even number.
- 11Programming ConceptWrite a program using any object-oriented language (e.g., C++ / Java / Python) to represent a Bank Account. Your program should include:
. A class BankAccount with data members for account holder's name, account number, and balance.
. Member functions to deposit() money, withdraw() money (ensuring sufficient balance), and display() account details.
Demonstrate the concept of encapsulation by keeping data member's private and providing appropriate public methods for accessing and modifying them.Combined Bank, SO-IT, 25 | Senior Officer (IT)#include <iostream> using namespace std; class BankAccount { private: string name; int accountNumber; double balance; public: void setDetails(string n, int accNo, double bal) { name = n; accountNumber = accNo; balance = bal; } void deposit(double amount) { balance += amount; cout << "Deposited: " << amount << endl; } void withdraw(double amount) { if (amount <= balance) { balance -= amount; cout << "Withdrawn: " << amount << endl; } else { cout << "Insufficient balance" << endl; } } void display() { cout << "\nAccount Details\n"; cout << "Account Holder: " << name << endl; cout << "Account Number: " << accountNumber << endl; cout << "Balance: " << balance << endl; } }; int main() { BankAccount acc; string name; int accNo; double bal, dep, wit; cout << "Enter account holder name: "; getline(cin, name); cout << "Enter account number: "; cin >> accNo; cout << "Enter initial balance: "; cin >> bal; acc.setDetails(name, accNo, bal); cout << "Enter amount to deposit: "; cin >> dep; acc.deposit(dep); cout << "Enter amount to withdraw: "; cin >> wit; acc.withdraw(wit); acc.display(); return 0; }
Sample I/O: Enter account holder name: itjobqns Enter account number: 02252016 Enter initial balance: 5000 Enter amount to deposit: 300 Deposited: 300 Enter amount to withdraw: 100 Withdrawn: 100 Account Details Account Holder: itjobqns Account Number: 2252016 Balance: 5200 === Code Execution Successful ===🔗 Run Online: Bank Balance & Deposit.
- 12Programming ConceptWhat is the difference between exception and Error in java?SPCBL, SAP, 22 |
Difference between Exception and Error in Java
- Meaning: Exception represents conditions that a program can handle; Error represents serious problems that a program cannot handle.
- Recovery: Exceptions can be caught and handled using try-catch; Errors are generally not recoverable.
- Cause: Exceptions occur due to logical issues or user input; Errors occur due to system-level failures.
- Examples: Exception – NullPointerException, ArithmeticException; Error – OutOfMemoryError, StackOverflowError.
- Package: Both belong to java.lang package, but Error is not meant to be handled.
Java-তে Exception এবং Error-এর পার্থক্য
- অর্থ: Exception হলো এমন সমস্যা যা program handle করতে পারে; Error হলো গুরুতর সমস্যা যা program handle করতে পারে না।
- Recovery: Exception try-catch দিয়ে handle করা যায়; Error সাধারণত recover করা যায় না।
- কারণ: Exception হয় logical সমস্যা বা ভুল input-এর কারণে; Error হয় system-level failure-এর কারণে।
- উদাহরণ: Exception – NullPointerException, ArithmeticException; Error – OutOfMemoryError, StackOverflowError।
- Package: দুটোই java.lang package-এর অন্তর্ভুক্ত, তবে Error handle করার জন্য নয়।
- 13Programming ConceptWhat is exception handling? Write with an example.SPCBL, SAP, 22 |
Exception Handling
Exception handling is a mechanism used in programming to handle runtime errors so that the normal flow of the program is not interrupted. It helps detect errors and provides a way to recover from them.
Example (Java):
try { int a = 10; int b = 0; int c = a / b; System.out.println(c); } catch (ArithmeticException e) { System.out.println("Division by zero is not allowed"); }Here, the exception is caught and handled instead of crashing the program.
Exception Handling
Exception handling হলো programming-এর একটি পদ্ধতি যেখানে runtime error ঘটলে তা handle করা হয়, যাতে program হঠাৎ বন্ধ না হয়ে যায় এবং স্বাভাবিকভাবে চলতে পারে।
উদাহরণ (Java):
try { int a = 10; int b = 0; int c = a / b; System.out.println(c); } catch (ArithmeticException e) { System.out.println("Division by zero is not allowed"); }এখানে error ঘটলেও program বন্ধ না হয়ে error message দেখায়।
- 14Programming ConceptDifference between High level language low level languages with some example?SPCBL, SAP, 22 |

Examples:
- High-Level Languages: C, C++, Java, Python, etc.
- Low-Level Languages: Assembly Language, Machine Code.
- 15Programming ConceptWrite a program in any language that takes two matrices A and B as inputs ensure your code handles matrices of different dimensions-
A) Find matrices C that is multiplication A and B.
B) Find average in A and B.
C) Max from matrices C 10CB, SO(IT), 23 | Senior Officer (IT)#include <iostream> using namespace std; void matrix_multiply(int A[10][10], int B[10][10], int C[10][10], int m, int n, int p, int q) { if (n != p) { cout << "Matrices A and B cannot be multiplied due to incompatible dimensions.\n"; return; } for (int i = 0; i < m; i++) { for (int j = 0; j < q; j++) { C[i][j] = 0; for (int k = 0; k < n; k++) { C[i][j] += A[i][k] * B[k][j]; } } } } float calculate_average(int matrix[10][10], int m, int n) { int sum = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { sum += matrix[i][j]; } } return static_cast(sum) / (m * n); } int find_max(int matrix[10][10], int m, int n) { int max = matrix[0][0]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (matrix[i][j] > max) { max = matrix[i][j]; } } } return max; } int main() { int A[10][10], B[10][10], C[10][10]; int m, n, p, q; cout << "Enter the number of rows and columns for matrix A (m x n): "; cin >> m >> n; cout << "Enter the number of rows and columns for matrix B (p x q): "; cin >> p >> q; if (n != p) { cout << "Matrices A and B cannot be multiplied due to incompatible dimensions.\n"; return 0; } // Input matrices A and B cout << "Enter elements of matrix A:\n"; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cin >> A[i][j]; } } cout << "Enter elements of matrix B:\n"; for (int i = 0; i < p; i++) { for (int j = 0; j < q; j++) { cin >> B[i][j]; } } // A) Multiply matrices A and B matrix_multiply(A, B, C, m, n, p, q); cout << "Matrix C (A x B):\n"; for (int i = 0; i < m; i++) { for (int j = 0; j < q; j++) { cout << C[i][j] << " "; } cout << endl; } // B) Calculate the average of matrices A and B float average_A = calculate_average(A, m, n); float average_B = calculate_average(B, p, q); cout << "Average of Matrix A: " << average_A << endl; cout << "Average of Matrix B: " << average_B << endl; // C) Find the maximum value in matrix C int max_C = find_max(C, m, q); cout << "Maximum value in Matrix C: " << max_C << endl; return 0; }Sample I/O: Enter the number of rows and columns for matrix A (m x n): 3 3 Enter the number of rows and columns for matrix B (p x q): 3 3 Enter elements of matrix A: 1 5 7 6 3 2 69 7 12 Enter elements of matrix B: 45 63 2 9 8 7 12 10 3 Matrix C (A x B): 174 173 58 321 422 39 3312 4523 223 Average of Matrix A: 12.4444 Average of Matrix B: 17.6667 Maximum value in Matrix C: 4523 === Code Execution Successful ===🔗 Run Online: Matrix Calculation
- 16Programming ConceptWrite a Program to find summation for a number until it's become single digit.Sonali, O(it), 21 | Bank
#include <iostream> using namespace std; int singleDigit(int n) { int sum = n; // Repeatedly calculate sum of digits until it becomes a single digit while (sum >= 10) { int tempSum = 0; // Calculate sum of digits of the number while (sum > 0) { tempSum += sum % 10; sum /= 10; } sum = tempSum; // Update sum to the sum of digits } return sum; } int main() { int n; // Taking user input cout << "Enter a number: "; cin >> n; // Calling the function and printing the result cout << "The single digit sum is: " << singleDigit(n) << endl; return 0; }
Input: n = 1234
Output: 1
Explanation:
Step 1: 1 + 2 + 3 + 4 = 10
Step 2: 1 + 0 = 1Input: n = 5674
Output: 4
Explanation:
Step 1: 5 + 6 + 7 + 4 = 22
Step 2: 2 + 2 = 4 - 17Programming ConceptFind the output of the following program.i=5;
While (i>=0)
printf("%d", i);
i=i-1;
}Sonali, O(it), 21 | Bank543210
- 18Programming ConceptFind the output of the following program.int main() {
printf ("%d\t", sizeof (6.5));
printf ("%d\t", sizeof(90000));
printf ("%d\t", sizeof ("A"));
return 0; }Sonali, O(it), 21 | BankOutput:
8 4 2- sizeof(6.5): 6.5 is a double in C, and the size of a double is typically 8 bytes. Thus, it will print 8.
- sizeof(90000): 90000 is an integer, and the size of an integer in C is typically 4 bytes. Thus, it will print 4.
- sizeof("A"): "A" is a string literal, and a string in C is stored as an array of characters, including the null terminator. Since "A" consists of 2 characters (A and '\0'), it will print 2.
- 19Programming ConceptWrite a function to find the smallest element from an arrayCB, AP, 23 | Bank
Algorithm to Find the Smallest Element in an Array
START
Step 1 → Initialize an array
Awith given values.
Step 2 → Create a variablemin_valueand set it to a large number (e.g., infinity) or the first element of the array.
Step 3 → Loop through each elementA[i]in the array starting from the first element.
Step 4 → For each element, check ifA[i]is smaller thanmin_value.
Step 5 → IfA[i] < min_value, updatemin_valuetoA[i].
Step 6 → Repeat Steps 4 and 5 until all elements have been checked.
Step 7 → Displaymin_valueas the smallest element of the array.STOP
#include <stdio.h> int findSmallest(int arr[], int size) { // 1. Assume the first number is the smallest int smallest = arr[0]; // 2. Look at the rest of the numbers one by one for (int i = 1; i < size; ++i) { // 3. If we find a number that is smaller, save it if (arr[i] < smallest) { smallest = arr[i]; } } // 4. Send back the smallest number we found return smallest; } - 20Programming ConceptWrite a Program to print Prime numbers from 1 to n.Combined Bank, AP, 24 | Bank
#include <iostream> using namespace std; int main() { int i, num, n, count; cout << "Enter the range: "; cin >> n; cout << "The prime numbers in between the range 1 to " << n << " are: "; for (num = 1; num <= n; num++) { count = 0; for (i = 2; i <= num / 2; i++) { if (num % i == 0) { count++; break; } } if (count == 0 && num != 1) cout << num << " "; } return 0; }Sample I/O: Enter the range: 50 The prime numbers in between the range 1 to 50 are: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 === Code Execution Successful ===🔗 Run Online: Prime number between range
- 21Programming ConceptWrite a Program to print Floyd's Triangle for n = 5.
Expected Output:
1
01
101
0101
10101Combined Bank, AP, 24 | Bank#include <iostream> using namespace std; int main() { int i, j, n, p, q; cout << "Input number of rows: "; cin >> n; for (i = 1; i <= n; i++) { if (i % 2 == 0) { p = 1; q = 0; } else { p = 0; q = 1; } for (j = 1; j <= i; j++) { if (j % 2 == 0) cout << p; else cout << q; } cout << endl; } return 0; }Sample I/O: Input number of rows: 6 1 01 101 0101 10101 010101 === Code Execution Successful ===🔗 Run Online: Floyd's Triangle
- 22Programming ConceptWrite a C++ program to find the sum of the series: 1 + 2 + 4 + 7 + 11 + ... + N.Combined Bank, AP, 24 | Bank
#include <iostream> using namespace std; int main() { int n, i, sum = 0, term = 1, nextTerm; cout << "Enter the value of n: "; cin >> n; cout << "The series is: "; for (i = 1; i <= n; i++) { cout << term << " "; sum += term; nextTerm = term + i; term = nextTerm; } cout << "\nThe sum of the series is: " << sum << endl; return 0; }Sample I/O: Enter the value of n: 10 The series is: 1 2 4 7 11 16 22 29 37 46 The sum of the series is: 175 === Code Execution Successful ===🔗 Run Code: Sum of series: 1+2+4+7+11+...+N - 23Programming ConceptFind the output of the following recursion:
#include <stdio.h>
void fun(int x){
if(x<0){
return;
}
printf("%d\n", x--);
fun(--x);
printf("%d\n", x);
}
int main() {
fun(5);
return 0;
}Combined Bank, AP, 24 | Bank
Step-by-Step Execution
Initial call:
fun(5)x = 5- Print
5 x--(post-decrement) → Passx = 4tofun(--x)
Recursive call:
fun(3)x = 3- Print
3 x--(post-decrement) → Passx = 2tofun(--x)
Recursive call:
fun(1)x = 1- Print
1 x--(post-decrement) → Passx = 0tofun(--x)
Recursive call:
fun(-1)x = -1- The
if(x<0) return;triggers, stopping recursion. - Nothing is printed here.
Returning from
fun(1):x = -1at this point (becausexwas decremented before recursion)- Print
-1
Returning from
fun(3):x = 1- Print
1
Returning from
fun(5):x = 3- Print
3
- 24Programming ConceptGiven two integers A and B as input write a program to compute the least common multiple of A and B.BB, AP, 23 | Bangladesh Bank
#include <stdio.h> int main () { int n1, n2, max; printf ("Enter two positive integers: "); scanf ("%d %d", &n1, &n2); // maximum number between n1 and n2 is stored in max max = (n1> n2) ? n1: n2; while (1) { // Check if max is divisible by both n1 and n2 if ((max% n1 == 0)&& (max % n2 ==0)) { // If true, max is the LCM of n1 and n2 printf("The LCM of %d and %d is %d.", n1,n2,max); break; } ++max; } return 0; }
Sample I/O: Enter two positive integers: 14 8 The LCM of 14 and 8 is 56. === Code Execution Successful ===🔗 Run Online: LCM of two integer
- 25Programming ConceptConsider the following code:
Public class Class A {
Mention which of the methods overload, override and hied supper class methods. What about the remaining method?
Public void m1 () {}
Public void m2 (int i) {}
Public void m3 (int i) {}
Public static void m4 (int i) {}
Public class class B extends class A {
Public static void ml (int i) {}
Public void m2 (int i) {}
Public void m3 (string s) {}
Public static void m4 (int i) {}BB, AP, 23 | Bangladesh Bank
- 26Programming ConceptString reverse program but without using new storage.SB & JB, ADA, 22 |
#include <bits/stdc++.h> using namespace std; int main() { string s; cout << "Enter String: "; cin >> s; int n = s.length(); int start = 0, end = n - 1; while (start < end) { // XOR-based swapping without using extra storage s[start] ^= s[end]; s[end] ^= s[start]; s[start] ^= s[end]; start++; end--; } cout << "Reverse String = " << s << endl; return 0; }Sample I/O: Enter String: itjobqns Reverse String = snqbojti === Code Execution Successful ===
- 27Programming ConceptBasicWrite a program for the following series: e^x = 1 + x/1! + x²/2! + x³/3! + ...Sonali Bank, ADA, 24 | Bank
#include <stdio.h> int main() { int n, i; float x, sum = 1, term = 1; printf("Enter value of x: "); scanf("%f", &x); printf("Enter number of terms: "); scanf("%d", &n); // Calculate series for (i = 1; i <= n; i++) { term = term * x / i; // x^i / i! sum = sum + term; } printf("Value of e^x = %.4f\n", sum); return 0; } - 28Programming ConceptBasicWrite a program for following sequence and analyze complexity of the program
1, 2, 2, 3, 3, 3, ……………………..100 (100times )CB, O(IT), 23 | Bank#include <iostream> using namespace std; int main() { // Loop from 1 to 100 for (int n = 1; n <= 100; n++) { // Inner loop to repeat 'n' exactly 'n' times for (int i = 0; i < n; i++) { cout << n << " "; } } cout << endl; // Print a newline at the end of the sequence return 0; }🔗 Run Online: Printing Sequence
- 29Programming ConceptBasicWrite a function which receives an array of integers as parameter and print the numbers divisible by 3 in the array.Combined Bank, O(IT), 24 | Bank
#include <stdio.h> void printDivisibleBy3(int arr[], int size) { for (int i = 0; i < size; i++) { if (arr[i] % 3 == 0) { printf("%d\n", arr[i]); } } } int main() { int size; printf("Enter the number of elements: "); scanf("%d", &size); int numbers[size]; // Variable Length Array (VLA) printf("Enter %d numbers:\n", size); for (int i = 0; i < size; i++) { scanf("%d", &numbers[i]); } printf("Numbers divisible by 3:\n"); printDivisibleBy3(numbers, size); return 0; }Sample I/O: Enter the number of elements: 6 Enter 6 numbers: 5 6 9 12 8 11 Numbers divisible by 3: 6 9 12 === Code Execution Successful ===🔗Run Online: Divisible by 3 in the array.
- 30Programming ConceptPointer#include
int main() {
int ledger[5] = {10, 20, 30, 40, 50};
int *ptr1 = (int *)(&ledger + 1);
int *ptr2 = (int *)(ledger + 1);
printf("%d, %d", *(ptr1 - 1), *(ptr2 + 2));
return 0;
}
Find the output.Combined Bank, AP-23, 26 | BankCode:
#include <stdio.h> int main() { int ledger[5] = {10, 20, 30, 40, 50}; int *ptr1 = (int *)(&ledger + 1); int *ptr2 = (int *)(ledger + 1); printf("%d, %d", *(ptr1 - 1), *(ptr2 + 2)); return 0; }Output:
50, 40Step-by-Step Explanation
1. Array Layout in Memory

2. ptr1 = (int *)(&ledger + 1)
- &ledger is a pointer to the entire array, type int (*)[5].
- &ledger + 1 moves forward by the size of the whole array (5 ints = 20 bytes), landing just after the array.
- ptr1 now points to memory right after ledger[4].
3. ptr2 = (int *)(ledger + 1)
- ledger decays to pointer to first element (int *).
- ledger + 1 moves to ledger[1], which contains 20.
- ptr2 points to ledger[1].
4. *(ptr1 - 1)
- ptr1 is just past the array end.
- ptr1 - 1 moves back to ledger[4].
- Value = 50.
5. *(ptr2 + 2)
- ptr2 points to ledger[1].
- ptr2 + 2 lands on ledger[3].
- Value = 40.
- 31Programming ConceptOthersWrite a program in any language to find the sum of rows and columns of a m X n matrix, where m and n is taken input from the user. Give the output in the following format:
Combined Bank, SO(IT), 24 | Senior Officer (IT)✅ C Program to Compute Row and Column Sum of a Matrix
#include <stdio.h> int main() { int m, n, i, j; // Input matrix dimensions printf("Enter the number of rows (m): "); scanf("%d", &m); printf("Enter the number of columns (n): "); scanf("%d", &n); int matrix[m][n]; // Input matrix elements printf("Enter the elements of the matrix row-wise:\n"); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { scanf("%d", &matrix[i][j]); } } // Calculate and print row sums printf("\nMatrix with Row Sums:\n"); for (i = 0; i < m; i++) { int rowSum = 0; for (j = 0; j < n; j++) { printf("%d ", matrix[i][j]); rowSum += matrix[i][j]; } printf("%d\n", rowSum); // Row sum } // Calculate and print column sums printf("\nColumn Sums:\n"); for (j = 0; j < n; j++) { int colSum = 0; for (i = 0; i < m; i++) { colSum += matrix[i][j]; } printf("%d ", colSum); } return 0; }Sample I/O:Enter the number of rows (m): 3 Enter the number of columns (n): 4 Enter the elements of the matrix row-wise: 1 3 4 2 2 4 5 3 3 2 2 5 Output: Matrix with Row Sums: 1 3 4 2 10 2 4 5 3 14 3 2 2 5 12 Column Sums: 6 9 11 10🔗Sum of rows and columns of a m X n matrix.
- 32Programming ConceptOthersWrite a program in any language to find the prime numbers between 1....... n, where n is taken as user input.
Sample input:
Enter value of n: 20
Sample Output:
Prime Numbers: 2, 3, 5, 7, 11, 13, 17, 19Combined Bank, SO(IT), 24 | Senior Officer (IT)#include <iostream> using namespace std; bool isPrime(int num) { if (num < 2) return false; for (int i = 2; i * i <= num; i++) { if (num % i == 0) return false; } return true; } void findPrimes(int n) { cout << "Prime Numbers: "; for (int i = 1; i <= n; i++) { if (isPrime(i)) cout << i << " "; } cout << endl; } int main() { int n; cout << "Enter value of n: "; cin >> n; findPrimes(n); return 0; }Sample I/O:Enter value of n: 20 Prime Numbers: 2 3 5 7 11 13 17 19🔗 Run Online: Prime Number between Range
- 33Programming ConceptOthersSuppose we want to develop software for a graphic package and we are given the task to implement circle class. The circle class has to be translatable from its origin. And it should also be able to give perimeter and area of the circle. Identify the data and method requirements for the class and give the data flow of translation method.Combined Bank, O(IT), 24 | Bank
✅ Identifying Data and Methods
Data Requirements (Attributes):
- x: X-coordinate of the center.
- y: Y-coordinate of the center.
- radius: Radius of the circle.
Method Requirements (Functions):
- Constructor: Initializes the circle with given coordinates and radius.
- translate(dx, dy): Moves the circle to a new position by updating its coordinates.
- getPerimeter(): Computes the perimeter using the formula: \[ P = 2\pi r \]
- getArea(): Computes the area using the formula: \[ A = \pi r^2 \]
- printCircle(): Displays the current position and radius of the circle.
✅ Implementation in C++
#include <iostream>
#include <cmath>
class Circle {
private:
double x, y, radius;
public:
// Constructor
Circle(double x, double y, double radius) {
this->x = x;
this->y = y;
this->radius = (radius > 0) ? radius : 1.0;
}
// Translate method
void translate(double dx, double dy) {
x += dx;
y += dy;
}
// Compute perimeter
double getPerimeter() const {
return 2 * M_PI * radius;
}
// Compute area
double getArea() const {
return M_PI * radius * radius;
}
// Print circle details
void printCircle() const {
std::cout << "Circle at (" << x << ", " << y << ") with radius "
<< radius << std::endl;
}
};
// Main function
int main() {
Circle c(0.0, 0.0, 5.0);
c.printCircle();
std::cout << "Perimeter: " << c.getPerimeter() << std::endl;
std::cout << "Area: " << c.getArea() << std::endl;
c.translate(3.0, 4.0);
std::cout << "After translation: " << std::endl;
c.printCircle();
return 0;
}✅ Data Flow of the
translateMethodInput:
Translation values
dxanddyare passed to thetranslatemethod.Process:
- The method adds
dxto the current X-coordinate. - The method adds
dyto the current Y-coordinate.
Output:
The updated coordinates
(x', y')reflect the new position of the circle.
- 34Programming ConceptrecursionFind the output of following program:
int F(n) {
if n == 0
return 0;
if n == 1
return 1;
return F(n-2)+F(n-1);
}
int main () {
result F(5);
}CB, O(IT), 23 | BankThe output of the program will be
5.Code Analysis
- Function
F(n):- The function calculates the Fibonacci number for a given
nusing recursion. - Base Cases:
- If
n == 0, it returns 0. - If
n == 1, it returns 1.
- If
- Recursive Case:
- For other values of
n, it returnsF(n-2) + F(n-1).
- For other values of
- The function calculates the Fibonacci number for a given
- Main Function:
- The main function calls
F(5)and stores the result (though it should be assigned to a variable likeresult).
- The main function calls
Calculation of
F(5)The Fibonacci sequence calculated by the function is:
F(5) = F(4) + F(3) F(4) = F(3) + F(2) F(3) = F(2) + F(1) F(2) = F(1) + F(0)Breaking it down:
F(2) = 1 (F(1) + F(0) = 1 + 0) F(3) = 2 (F(2) + F(1) = 1 + 1) F(4) = 3 (F(3) + F(2) = 2 + 1) F(5) = 5 (F(4) + F(3) = 3 + 2) - Function
- 35Programming ConceptArrayWrite the pseudocode/ program (in any language) to print the common element between two arrays and the total number of such elements found. [assume each element in an array distinct].BB, AD(ICT), 25 | Bangladesh Bank
#include <iostream> using namespace std; int main() { int size1, size2; // Taking input size of first array cout << "Enter size of first array: "; cin >> size1; int arr1[size1]; cout << "Enter elements of first array:\n"; for (int i = 0; i < size1; i++) { cin >> arr1[i]; } // Taking input size of second array cout << "Enter size of second array: "; cin >> size2; int arr2[size2]; cout << "Enter elements of second array:\n"; for (int i = 0; i < size2; i++) { cin >> arr2[i]; } // To store common elements int commonElements[size1 < size2 ? size1 : size2]; int count = 0; // Check each element in arr1 against arr2 for (int i = 0; i < size1; i++) { bool found = false; for (int j = 0; j < size2; j++) { if (arr1[i] == arr2[j]) { found = true; break; } } if (found) { // Check for duplicates bool alreadyExists = false; for (int k = 0; k < count; k++) { if (commonElements[k] == arr1[i]) { alreadyExists = true; break; } } if (!alreadyExists) { commonElements[count] = arr1[i]; count++; } } } // Print common elements cout << "Common elements: "; for (int i = 0; i < count; i++) { cout << commonElements[i] << " "; } cout << endl; // Print total count cout << "Total number of common elements: " << count << endl; return 0; }Sample I/O: Enter size of first array: 5 Enter elements of first array: 0 20 30 40 50 Enter size of second array: 6 Enter elements of second array: 10 2 20 30 60 90 Common elements: 20 30 Total number of common elements: 2 === Code Execution Successful ===🔗 Run Online: Print Common Elements Between Two Arrays
Previous Year MCQ Question
{
int x=3; int y=2;
if (x==2)
y=3;
else
y=2;
printf("%d %d\n", x, y);
}
2,3








