Wipro - C & C++ Coding Ability

Test Number 5


You are given an integer N. Your task is to check whether the number is even or odd.

INPUT:
First line fo input contains the T test cases.

Second line contains an integer.

OUTPUT:

Contains a string which is either odd or even.

Test Case: 1

INPUT:
1

23

OUTPUT:
odd                

#include < bits/stdc++.h>

using namespace std;

int main()

{

    int T;

    cin >> T;

    while(T--)

    {

        int N;

        cin>>N;

        if(N%2==0)

        {

            cout<<"even"< < endl;

        }

        else

        cout << "odd" << endl;

    }

    return 0;

    

}               






You are given a positive integer N. The task is to find how many numbers less than or equal to N have numbers of divisors exactly equal to 3.

INPUT:
First Line of the input contains the number of test cases T. 

For each test case the next line contains an integer N.

OUTPUT:
For each test case there will be an integer showing the number of total divisors.



Test Case: 1

INPUT:
1

8

OUTPUT:
1

Explanation:

The only number which have exactly 3 divisors and is less than 8 is 4.

so answer will be 1.                   

#include 

using namespace std;



class Solution{

    public:

    int exactly3Divisors(int N)

    {

       

        int count = 0;

        for (int i = 1; i*i <= N; i++) 

        {

            if(isprime(i)) count++;

        }

        return count;

    }

    

    bool isprime(int n)

    {

        if(n == 1) return false;

        if(n == 2 || n == 3) return true;

        if(n % 2 == 0 || n % 3 == 0) return false;

        for(int i = 5; i*i <= n; i = i+6) 

        {

            if ( (n % i) == 0 || (n % (i+2)) == 0) return false;

        }

        return true;

    }

};









int main()

 {

    int T;

    

    

    cin>>T;

    while(T--)

    {

        int N;

        

       

        cin>>N;

        Solution ob;

        

        cout<< ob.exactly3Divisors(N)<






Your task is to find the factorial of first N natural numbers.

INPUT:

First Line of input contains T no. of Test cases.

For each test case the second line contains an integer value.

OUTPUT:
Contains an integer value that is the product of N natural numbers



Test Case: 1

INPUT:
1

5



OUTPUT:
120



Explanation :

Product of 5 natural numbers 1 *  2 * 3 * 4 * 5 = 120                          

#include

using namespace std;

int main()

{

    int T;

    cin >> T;

    int N;

    cin >> N;

    int sum = 1;

    

    for (int i=1; i<=N; i++ )

    {

        sum *= i;

    }

    cout << sum;

}                          






Your task is to find the factorial of a given number.

INPUT:
take input of an integer

OUTPUT:

it contains the factorial of that given integer.                     

#include

#include

 main()

{

	int i,n,pro=1;

	printf("Enter the value of n to find factorial\n");

	scanf("%d",&n);

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

	

		pro=pro*i;

		printf("the value of factorial %d is %d",n,pro);

		

	

	getch();

}                             






You are given a set of natural numbers from 1 to N. Every number is present twice times in the set. Your task is to find the worst case scenario of the set in which we required maximum steps to find our first matching pair.

INPUT:

First Line of input contains T test cases.

For each test case the next line contains the value of N.

 OUTPUT:
Contains a single integer.


TEST CASE: 1
INPUT:

1

2

OUTPUT:
3



Explanation:

For N=2, There are two matching pairs possible. Then the worst case for this set is {1,2,1,2}. For this case the steps taken for our first matching pair found is 3 so the answer is 3.                    

#include 

using namespace std;



class Solution{

public:

    int find(int N){ 

        

        return N+1;

    }

};



int main() 

{ 

    int t;

    cin>>t;

    while(t--)

    {

        int N;

        cin>>N;

        Solution ob;

        cout << ob.find(N) << endl;

    }

    return 0; 

}