Programming Question
Write 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].Bangladesh Bank (AD(ict)), 2025
#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

Write 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)), 2025
#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.

Write a function which receives an array of integers as parameter and print the numbers divisible by 3 in the array. CB, Officer (it), 2025
#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.

Write 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. 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 ===
        


🔗 Run Online: Bank Balance & Deposit.

Suppose you are working with an array of size 10. It contains all the numbers from 1 to 10 exactly once in a random order. But accidentally, one of the numbers in the array got replaced by a zero (0). Write a C/C++ programme using functions, to restore the lost number. [Ministry of food, network/website Manager(ICT),2025]
#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;
}
Write 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)), 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


🔗 Run Online: Prime Number between Range

Write 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)), 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


🔗Sum of rows and columns of a m X n matrix.

Write a Program to print Prime numbers from 1 to n. Combined Bank (AP), 2024
#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

Write a Program to print Floyd's Triangle for n = 5. Combined Bank (AP), 2024
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 ===


🔗 Run Online: Floyd’s Triangle

Write a C++ program to find the sum of the series: 1 + 2 + 4 + 7 + 11 + ... + N. Combined Bank (AP), 2024
#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

Write a C Program to generate the Fibonacci series n number of times.Dutch Bangla Bank, MTO, 24
#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
Write a program that take input an array with positive and negative number and rearrange this with positive to negative.Dutch Bangla Bank, MTO, 24

#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
Write a program that takes input for date, month, and year, and verifies if the given date is valid. If valid, display "Valid Date", otherwise display "Invalid Date". Also, explain how leap years are handled in your program.Dutch Bangla Bank, MTO, 24
#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.

Write a program that check a number is prime number.ICB, AP, 24
#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;
}
Consider the following code snippet in a C like Programming language -

int a = 5, b= 18, c = 27,
a=b++ + ++c;
b = a++ - c --;
c= a++ + b --;

What will be the output of a, b, and c after execution of the above statements? Explain your answer.46 BCS, Computer Science

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
একটি C program লিখুন যা একটি 5-digit সংখ্যার সকল digit-এর যোগফল নিরূপণ করতে পারে। 45 BCS,Computer Science(971)
#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;
}


🔗Run Online: Sum of Digit

Using recursion, develop a computer program to find the n-th Fibonacci number using this rule.[ BPSC AME)-24]
#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;
}
Write a program for the following series: e^x = 1 + x/1! + x²/2! + x³/3! + ...Sonali Bank, ADA, 2024
#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;
}
Write a program for following sequence and analyze complexity of the program
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;
}


🔗 Run Online: Printing Sequence

Find 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);
}

Sonali and Janata Bank, O(it), 2023

The output of the program will be 5.

=====================

Code Analysis

  1. Function F(n):
    • The function calculates the Fibonacci number for a given n using recursion.
    • Base Cases:
      • If n == 0, it returns 0.
      • If n == 1, it returns 1.
    • Recursive Case:
      • For other values of n, it returns F(n-2) + F(n-1).
  2. Main Function:
    • The main function calls F(5) and stores the result (though it should be assigned to a variable like result).

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)

Write 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 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
Find the output of the following program including time and space complexity

#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)

Write a function to find the smallest element from an arrayCB, AP, 2023

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;
}
Given two integers A and B as input write a program to compute the least common multiple of A and B.BB, AP, 2023
#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

Topic Wise Question Bank
programming concept
Find the output:
int main()
{
int x=3; int y=2;
if (x==2)
y=3;
else
y=2;
printf("%d %d\n", x, y);
}
Bangladesh Bank (AD(ict)), 2025

2,3

Coming SOON
Coming Soon
WhatsApp Telegram Messenger