Wipro - C & C++ Coding Ability

Test Number 11


You are given an array of size N.

Your task is to arrange all the elements of that array in such a manner that all the zeroes will push to the last of the array.  The order of all other elements should be same.

INPUT:
First line of the input contains an integer N. 

Next line of the input contains N space separated integers. 

OUTPUT:

First line of the output conains N space separated integers which are the final output array



Test Case: 1

INPUT:

5

2 0 4 0 5



OUTPUT:
2 4 5 0 0                  

#include < iostream>

using namespace std;





void pushZerosToEnd(int arr[] , int n)

{

	int temp = 0; 

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

		if (arr[i] != 0)

			arr[temp++] = arr[i]; 

	while (temp < n)

		arr[temp++] = 0;

}





int main()

{

	int n;

	cin >> n;

	int arr[n];

	for(int j=0; j< n ; j++)

	{

	    cin >> arr[j];

	}

	pushZerosToEnd(arr, n);

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

		cout << arr[i] << " ";

	return 0;

}               






You are given a number N. Your task is to print the multiplication table of the given number.

INPUT:
First Line contains the T test cases.

For each test case, the next line contains a single integer value.

OUTPUT:
Contains 10 space separated integers.



Test Case: 1

INPUT:
1

7

OUTPUT:
7 14 21 28 35 42 49 56 63 70                   

#include 

using namespace std;

int main()

{

    int T;

    cin >> T;

    while(T--)

    {

        int N;

        cin>>N;

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

        {

            cout<< i*N << " ";

        }

    }

    return 0;

    

}                   






You are given a positive integer N. Your task is to print Nth Natural number after removing all the numbers containing the value 7 in their divisor.

INPUT:
First line of input contains T for test cases.

For each test case, the next line contains a positive integer N.

OUTPUT:
Contains a positive integer indicating the value of the Nth number.



Examples:

Test Case: 1

INPUT:

1

6

OUTPUT:
6

Explanation:

After removing natural numbers which contains digit 7, first 6 numbers are 1,2,3,4,5,6
and 6th number is 6.

Test Case: 2

INPUT:
1

15

OUTPUT:
17

Explanation:

After removing natural numbers which contains digit 7, first 15 numbers are 1,2,3,4,5,6,8,9,10,11,12,13,15,16,17
and 15th number is 17.

                          

#include

using namespace std;



class Solution

{

	public:

    	long long findNth(long long N)

    {

        long long ans = 0;

        long long count = 1;

        while (N > 0) 

        {

            ans += (count * (N % 7));

            N = N / 7;

            count = count * 8;

            

        }

        return ans;

        

    }

};



int main()

{

	int T;

	cin>>T;

	while(T--)

	{

		long long n , ans;

		cin>>n;

		Solution obj;

		ans = obj.findNth(n);

		cout<< ans<< endl;

	}

}

                          






You are given a number N. Your task is to output the dame number. 

INPUT:
The first line of the input contains an integer N.

OUTPUT:
Contains an integer denoting the answer.


Test Case: 1

INPUT:
456

OUTPUT:
456                     

#include < stdio.h>



int main(void)

{

	int N;

	scanf("%d",&N);

	printf("%d",N);

	return 0;

}

                             






You are given a matrix of MxN size. Your task is to count all the possible paths from top left to the bottom right of an MxN matrix with the constraints that you can either move to the right or down from each cell.

INPUT:
First line of input contains T for test cases.

For each test case, the next line contains two positive integers denoting the values of m and n respectively.

OUTPUT:
Contains a single integer value denoting the count.



Explanation:

INPUT:
1

3 3

OUTPUT:
6

Explanation:

Let the given input 3*3 matrix is filled as such:
A B C
D E F
G H I
The possible paths which exists to reach 'I' from 'A' following above conditions 
are as follows:ABCFI, ABEHI, ADGHI, ADEFI, ADEHI, ABEFI
Test Case: 2
INPUT:
1 

2 6

OUTPUT:
6                    

#include 

using namespace std;



long long  numberOfPaths(int m, int n)

{



    if(m==0&&n==0)

    {

        return 0;

    }

    if(m==1||n==1)

    {

        return 1;

    }

    return numberOfPaths(m-1,n)+numberOfPaths(m,n-1);

}



int main()

{

	int T;

	cin>>T;

	while(T--)

	{

		int n,m;

		cin>>m>>n;

	    cout << numberOfPaths(m, n)<< endl;

	}

    return 0;

}