Ask Question - Get Answer

2 Ans BPSC aptitude test all programs solutions here

Asked by Birds of the sky (2 Golds) Monday, 03 Jan 2022, 09:22 PM at (Education Tutorials)

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

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

Answer(s):

1.      Prime Numbers 1 to N

 

 #include<stdio.h>

int main()

{

    int num,i,count,n;

    printf("Enter max range: ");

    scanf("%d",&n);

    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)

            printf("%d ",num);

    }


    return 0;

}



 

 

 

2.     Count Number of Word from a string

 

#include<stdio.h>

#include<string.h>

int main()

{

    char s[100];

    gets(s);

    int l=strlen(s);

    int count=1;

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

    {

        if(s[i]==' ')

        {

            count++;

        }

    }

    printf("= %d ", count);

    return 0;

}

 

 

 

3.     Reverse a String

 

#include<stdio.h>

#include<string.h>

int main()

{

    char s[100];

    gets(s);

    int l=strlen(s);

    for(int i=l-1; i>=0; i--)

    {

        printf("%c", s[i]);

    }

    return 0;

}

 

4.     Half Pyramid

 

*

**

***

****

*****

 

#include<stdio.h>

#include<string.h>

int main()

{

    int i, j, n;

    scanf("%d", &n);

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

    {

        for(j=i; j>=1; j--)

        {

            printf("*");

        }

        printf("n");

    }

    return 0;

}

 

5.     Half Inverted Pyramid

     

      ******

      ****

      ***

      **

      *

 

#include<stdio.h>

#include<string.h>

int main()

{

    int i, j, n;

    scanf("%d", &n);

    for(i=n; i>=1; i--)

    {

        for(j=i; j>=1; j--)

        {

            printf("*");

        }

        printf("n");

    }

    return 0;

}

 

6.     Print Prime Number 19 to 10

 

#include<stdio.h>

#include<string.h>

int isprime(int n)

{

    int i;

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

    {

        if(n%i==0)

            return 0;

    }

    return 1;

}

int main()

{

    int i, j, flag;

    for(i=19; i>=10; i--)

    {

        if(isprime(i) == 1)

        {

            printf("%d ", i);

        }

    }

 

    return 0;

}

 

7.     Program Takes input an Integer and Swap first digit with last digit

 

Input : 12345

Output : 52341

 

#include<stdio.h>

int main()

{

    int num,temp,r,digit[10],i,j;

    printf("enter number: ");

    scanf("%d",&num);

    i=0;

    temp=num;

    while(temp!=0)

    {

        r=temp%10;

        digit[i]=r;

        i++;

        temp=temp/10;

    }

    printf("after swaping: ");

    //printing last digit at first;

    printf("%d",digit[0]);

    //printing midle digit.

    for(j=i-2; j>0; j--)

    {

        printf("%d",digit[j]);

    }

    //printing first digit at last

    printf("%d",digit[i-1]);

}

 

8.    Uppercase Letter to Lowercase and

Lowercase to Uppercase Letter in a String

 

#include<stdio.h>

#include<string.h>

int main()

{

    char s[10];

    gets(s);

    int l = strlen(s);

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

    {

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

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

        else

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

    }

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

    {

        printf("%c", s[i]);

    }

    return 0;

}

 

9.     Input : 5

Output:

1

22

333

4444

55555

 

#include<stdio.h>

#include<string.h>

int main()

{

    int i, j, n;

    //scanf("%d", &n);

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

    {

        for(j=1; j<=i; j++)

        {

            printf("%d", i);

        }

        printf("n");

 

    }

    return 0;

}

 

 

10.   

Answered by Birds of the sky (2 Golds) Monday, 03 Jan 2022, 09:23 PM

Please log in to Upvote, Downvote and Report

Aptitude question 2018 

Answered by Birds of the sky (2 Golds) Wednesday, 05 Jan 2022, 03:53 PM

Please log in to Upvote, Downvote and Report
           

Related Q/A:

2 Ans Write a C program to implement Selection sort data structure and algorithm

1 Ans Write a C program to reverse a number

1 Ans Write a C program to check a Prime number

2 Ans BPSC aptitude test all programs solutions here

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

1 Ans Write a C program to find nth Fibonacci number

1 Ans Bank Exam all important Writing Materials

1 Ans Write a C program to Find Armstrong Number series upto a Number

1 Ans Write a C program to check a perfect number

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


AL MaMun (active on Monday, 06 Sep 2021, 11:15 AM) (4 Golds)
Birds of the sky (active on Wednesday, 27 Apr 2022, 12:16 PM) (2 Golds)
Tajrimun Elisha (active on Friday, 22 Nov 2019, 08:56 AM) (2 Golds)
Ghost (active on Saturday, 05 Jan 2019, 10:37 AM) (1 Silver)
Hena Begum (active on Friday, 15 Feb 2019, 11:04 PM) (8 Bronzes)
BrandonDug (active on Thursday, 17 Dec 2020, 05:25 AM) ( New Contributor )
Md Hasan (active on Saturday, 02 Nov 2019, 10:02 AM) (4 Bronzes)
APU KUMAR ROY (active on Sunday, 22 Sep 2019, 02:42 AM) (1 Bronze)
عبد الحنان سلفي (active on Friday, 28 Aug 2020, 05:04 PM) (2 Bronzes)
student (active on Monday, 27 Jul 2020, 07:28 PM) (2 Bronzes)
Jackson99 (active on Monday, 27 Apr 2020, 02:44 PM) ( New Contributor )
Hr Hannan (active on Tuesday, 11 Dec 2018, 12:28 PM) (2 Bronzes)
Miskatul Zannat Bristy (active on Friday, 16 Jul 2021, 02:08 AM) ( New Contributor )
Bongiyo Training (active on Wednesday, 30 Mar 2022, 02:57 PM) ( New Contributor )
G. M. Nasir Uddin Ahammad (active on Tuesday, 08 Mar 2022, 01:50 PM) (2 Bronzes)
MD SAIFUL ISLAM (active on Friday, 24 Jan 2020, 04:13 PM) ( New Contributor )
Daily Science (active on Friday, 03 Jan 2020, 07:52 PM) ( New Contributor )
Md Mondol (active on Tuesday, 23 Jul 2019, 10:28 PM) (2 Bronzes)
Hazrat (active on Sunday, 26 May 2019, 05:55 AM) (2 Bronzes)
Sowrov (active on Thursday, 14 Feb 2019, 10:48 AM) (7 Bronzes)
Show All Members

Online Now 1
Today's Unique PageViews 168
Today's Total PageViews 4052
Site's Total PageViews 3900439