Wipro - C & C++ Coding Ability

Test Number 6


You are given a positive integer N that represents the height of the triangle. Your task is to make a Floyd's Triangle of the given height.  Floyd's triangle is a triangular array of natural numbers and  is defined by filling the rows of the triangle with consecutive numbers, starting with a 1 in the top left corner.

 

INPUT:
First Line of the input contains the height of the triangle. 



OUTPUT:
Contains the pattern of the Floyd's Triangle.



Test Case: 1

INPUT:
5



OUTPUT:
1

2 3

4 5 6

7 8 9 10

11 12 13 14 15                

#include< iostream>

using namespace std;

int main()

{

	int h;

	cin>>h;

	

	int initial=1;

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

	{

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

		{

			cout<< initial <<" ";

			initial++;

		}

		cout<< endl;

	}

	return 0;

}               






You are given an array of length N containing the integers as input. The task is to find whether it’s possible to construct an integer using all the digits of these numbers such that it would be divisible by 3. If it is possible then print “1” and if not print “0”. 



 INPUT:

First line of input contains T for test cases.

For each test Case, the next line contains the size of the array

For next line contains N space separated integers denoting the elements of the array.



OUTPUT:
Containing 0 or 1 as output.



Test Case: 1

INPUT:
1

2 

3 6



OUTPUT:
1

Explanation:

From 3 and 6 we can make 36 and this is divisible by 3 so the answer is 1.

                   

#include 

using namespace std;



class Solution{

public:

    int isPossible(int N, int arr[])

    {

        int sum = 0;

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

        {

            sum = sum + arr[i];

        }

        int d=0;

        while(sum)

        {

            d = d + sum % 10;

            sum = sum/10;

        }

        if(d%3==0)

        {

            return 1;

        }

        return 0;

    }

};



int main(){

    int T;

    cin>>T;

    while(T--){

        int N;

        cin>>N;

        int arr[N];

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

            cin>>arr[i];

        

        Solution ob;

        cout<< ob.isPossible(N, arr)<






You are given two numbers. Your task is to find their GCD ( Greatest Common Divisor) and LCM ( Lowest Common Multiple). 

INPUT:
The first line contains an integer T, the total number of test cases. 

Then follow T lines, each line contains an integer A and B.

OUTPUT:
Display the GCD and LCM of the digits separated by space. 

The answer for each test case must be displayed in a new line.



Test Case: 1

INPUT:
1

40 60



OUTPUT:
20 120                          

#include

#include

using namespace std;

int main(){

    int T;

    cin>>T;

    while(T--)

    {

        long long int a,b;

        cin>>a>>b;

        long long int n = __gcd(a,b);

        long long int m = a*b/n;

        cout<< n<<" "<< m<< endl;

    }

    return 0;

}                          






In a company an emplopyee is paid as under: If his basic salary is less than Rs. 15000, then HRA = 10% of base salary and DA = 90% of basic salary.
If his salary is either equal to or above Rs. 15000, then HRA = Rs. 5000 and DA = 98% of basic salary. If the Employee's salary is input, write a program to find his gross salary.

NOTE: Gross Salary = Basic Salary + HRA + DA



INPUT:
The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer salary.



OUTPUT:
For each test case, output the gross salary of the employee in a new line.

Answer should be precise to 2 zeroes after decimal.



Test Case: 1

INPUT:
2

10000 20000



OUTPUT:

20000.00

44600.00

                     

#include 

using namespace std;



int main() 

{

	int T;

	cin>>T;

	while(T--)

	{

	    double salary;

	    cin>>salary;

	    if(salary< 15000)

	    {

	        cout<< fixed<< setprecision(2)<< salary+(salary*10)/100+(salary*90)/100<< endl;
 
	    }

	    else

	    {

	        cout<< fixed<< setprecision(2)<< salary + 5000 + (salary*98)/100<< endl;

	    }

	}

	return 0;

}                             






You are given two integers A and B. Your task is to half B by A-1 times and print the output after this operation.

INPUT:
First line of input contains T test cases.

For each test case, the next line contains two space-separated integers containing the values of B and A respectively. 

OUTPUT:
Contains a single integer indicating the final output.



Test Case: 1

INPUT:

1

200 6

OUTPUT:
6

Explanation: 

half 200 by 5 times 200 100 50 25 12 6

So after 5 halves, the answer is 6.                    

#include 

using namespace std;

int main()

{

    int T;

    cin>>T;

    while(T--)

    {

        int A, B;

        cin>>B>>A;

        while(A!=1)

        {

            B = B/2;

            A--;

        }

        cout<< B << endl;

    }

     return 0;

}