Ask Question - Get Answer

2 Ans BPSC aptitude test all programs solutions here

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

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

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

Answer(s):

Aptitude question 2018 

Answered by Birds of the sky (2 Golds) Thursday, 06 Jan 2022, 02:53 AM

Please log in to Upvote, Downvote and Report

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) Tuesday, 04 Jan 2022, 08:23 AM

Please log in to Upvote, Downvote and Report
           

Related Q/A:

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

1 Ans Write a C program to check a Prime number

2 Ans BPSC Programming Aptitude Lab Test Important programs

1 Ans Write a C++ program for BigMod math

1 Ans Write a C program to print Floyd Triangle

1 Ans Write a C program to find the highest and lowest number in a series

1 Ans Write a C program for Interest Calculation

1 Ans Write a C program to print Fibonacci number series

1 Ans Write a C program to implement x power n using recursion

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