Ask Question - Get Answer

3 Ans BPSC Assistant Programmer Lab Aptitude test Programs and Queries with Proper solution (Taken By BCC)

Asked by Birds of the sky (2 Golds) Tuesday, 04 Jan 2022, 08:00 AM at (Education Tutorials)

Please log in to answer, like and save
0
Save 0

<<< Previous
Log in to Answer Next >>>

Answer(s):

Date: 31 December 2021

BPSC Assistant Programmer 59 posts Lab aptitude test

1st Slot Question

1.      Write a C/C++ program to count digits and alphabets from a given string using a function (25 Marks)

2.      a) Write SQL query to find Minimum and Average salary from a given Employee table. b) Write a SQL Query to find 3rd Highest Salary (25 Marks)

 

Solution: (1st Slot)

 

1.      C program

 

#include<stdio.h>

#include<string.h>

void action(char *s, int l)

{

    int i=0, c=0, n=0;

    for(i=0; i<l; i++)

    {

        if((s[i]>='A' && s[i]<='Z') ||(s[i]>='a' && s[i]<='z'))

        {

            c++;

        }

        if(s[i]>='0' && s[i]<='9')

        {

            n++;

        }

    }

    printf("Character = %d", c);

    printf("nNumber =%d", n);

}

int main()

{

    char s[]="Digital Bangladesh 123";

    int l=strlen(s);

    action(s, l);

    return 0;

}

 

2.      a) SELECT MIN(salary), MAX(salary)  FROM employee WHERE age>32

 

             b) SELECT MAX(salary) FROM employee WHERE salary < (SELECT MAX(salary) FROM employee WHERE salary NOT IN (SELECT MAX(salary) FROM employee));

 

 

2nd Slot Question

1.      Write a C/C++ program that takes input 5 numbers in an Array and make sum the biggest and lowest number and check that sum is prime or not prime. (25 Marks)

2.      a) Write a SQL query to delete Duplicate rows from a given table. b) Write a SQL Query to retrieve the Employee name whose salary is greater than average salary (25 Marks)

 

Solution: (2nd Slot)

 

1.      C program Code:

 

#include<stdio.h>

#include<string.h>

int isPrime(int n)

{

    if(n == 0 || n == 1)

        return 0;

    int i;

    for(i=2; i<n; i++)

    {

        if(n%i==0)

            return 0;

    }

    return 1;

}

int main()

{

    int i, j, temp;

    int a[5];

    for(i=0; i<5; i++)

    {

        scanf("%d", &a[i]);

    }

    for(i=0; i<5; i++)

    {

        for(j=0; j<5-i-1; j++)

        {

            if(a[j]>a[j+1])

            {

                temp=a[j];

                a[j]=a[j+1];

                a[j+1]=temp;

            }

        }

    }

    for(i=0; i<5; i++)

    {

        printf("%d ", a[i]);

    }

 

    int num = a[0] + a[4];

    if(isPrime(num) == 1)

    {

        printf("Prime");

    }

    else

        printf("Not Prime");

    return 0;

}

 

 

2.      a) DELETE t1 from test t1 JOIN test t2 WHERE t1.id < t2.id AND t1.number = t2.number

 

b) SELECT emp_name, salary FROM employees WHERE salary > (SELECT AVG(salary) from employees)

 

 

 

 

 

 

Date: 01/01/2022

 

1st Slot Question with Solution:

 

1.      An Array of 5 numbers has given. Print the numbers between the lowest and highest number of this array which are not exists in this array.

Input: 8 2 5 6 10

Output: 3 4 7 9

 

Solution:

 

#include<stdio.h>

int action(int m[5], int s)

{

    int i;

    for(i=0; i<5; i++)

    {

        if(m[i]==s)

            return 0;

    }

    return 1;

}

 

int main()

{

    int n[5], temp, i, j, low, high, m=5;

    for(i=0; i<5; i++)

    {

        scanf("%d", &n[i]);

    }

 

    for(i=0; i<5; i++)

    {

        for(j=0; j<5-i-1; j++)

        {

            if(n[j]>n[j+1])

            {

                temp=n[j];

                n[j]=n[j+1];

                n[j+1]=temp;

            }

        }

    }

    low = n[0];

    high = n[4];

    for(i=low+1; i<high; i++)

    {

        if(action(n, i)==1)

        {

            printf("%d ", i);

        }

    }

 

    return 0;

}

 

2.

a) SQL Query for average run of player which home is Chittagong and show the result in average run descending order.

 

Solution:

SELECT i.AVG(run) as Average_run

FROM players p, innings i

WHERE p.address = “Chittagong”

Order by Average_run DESC;

 

b) SQL Query on the list of innings number on a specific value

 

Solution:

SELECT count(id) as innings

FROM innings

GROUP BY venue;

 

 

2nd Slot Question with Solution:

 

1.       

 

i)                    From a given string change small case vowel to capital case. If vowel already in capital case then no change

 

Solution:

 

#include<stdio.h>

#include<string.h>

int main()

{

    int l, i;

    char s[100];

    gets(s);

    l = strlen(s);

    for(i=0; i<l; i++)

    {

        if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u')

            s[i] = s[i] - 32;

    }

    puts(s);

    return 0;

}

 

 

ii)                  Capital consonant to small case, if consonant already in small case then no change

 

Solution:

 

#include<stdio.h>

#include<string.h>

int main()

{

    int l, i;

    char s[100];

    gets(s);

    l = strlen(s);

    for(i=0; i<l; i++)

    {

        if(s[i]!='a' && s[i]!='e' && s[i]!='i' && s[i]!='o' && s[i]!='u' && s[i]!='A' && s[i]!='E' && s[i]!='I' && s[i]!='O' && s[i]!='U')

        {

            if(s[i]>='A' && s[i]<='Z')

                s[i] = s[i] + 32;

        }

    }

    puts(s);

    return 0;

}

 

 

2.      a. count vaccinator who gave vaccine multiple days. (vaccinator can also give multiple vaccines on the same days)

 

Solution:


Select count(*) from (select count(distinct(date)) as vcc from vaccine_table group by vaccinator_ID  having vcc > 1) as t


(This Question can not be collected properly, especially needed the table columns)

 

 

b. Show database size in MB

 

Solution:

 

SELECT table_schema AS "Database",

ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"

 FROM information_schema.TABLES

GROUP BY table_schema;

 

 

Compiled By Mamun (www.facebook.com/mamuncse2015 )

Answered by Birds of the sky (2 Golds) Tuesday, 04 Jan 2022, 08:01 AM

Please log in to Upvote, Downvote and Report

View BPSC All Important Programs here

Answered by Birds of the sky (2 Golds) Tuesday, 04 Jan 2022, 08:19 AM

Please log in to Upvote, Downvote and Report

Previous Aptitude Test Program solution:

https://askunion.com/1162

Thanks. 

Answered by Birds of the sky (2 Golds) Tuesday, 04 Jan 2022, 08:24 AM

Please log in to Upvote, Downvote and Report
           

Related Q/A:

1 Ans Write a C program to print Fibonacci number using recursion

1 Ans Write a C program to implement Insertion sort data structure and algorithm

1 Ans Write a C++ program for BigMod math

3 Ans BPSC Assistant Programmer Lab Aptitude test Programs and Queries with Proper solution (Taken By BCC)

1 Ans Single Digit Interest Rate in the Banking Sector: Problems and Prospects - essay writing

1 Ans The general rules for constructing names for variables (unique identifiers)

3 Ans Three ways to find Greatest Common Divisor (GCD) and Least Common Multiple (LCM) in a C program

1 Ans A Quest for Peace in the Middle East: Recent Perspectives - composition

2 Ans BPSC aptitude test all programs solutions here

1 Ans Write a C program to print Floyd Triangle