Wipro - C & C++ Coding Ability

Test Number 15


You are given a number N. Your task is to find the smallest number which is divisible completely by all the integers from 1 to N.

Input:

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

For each test case, there present a number N.

Output:

For each test case there present an integer representing that smallest number.



Test Case: 1

INPUT:
1

3

OUTPUT:
6

Explanation :

6 is the smallest number which is divisible by 1,2,3.                

#include < bits/stdc++.h>

using namespace std;



class Solution{

public:

    long long getSmallestDivNum(long long n)

    {

        

        long long temp = 1;

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

        temp = (temp*i)/__gcd(temp,i);

        return temp;

    }

};



int main() {

    int t;

    cin>>t;

    while(t--)

    {

        int n;

        cin>>n;

        Solution ob;

        cout<< ob.getSmallestDivNum(n)<< endl;

    }

    return 0;

}               






You have given a sequence a1, a2, ..., aN. Your task is to find the smallest possible value of ai + aj, where 1 ≤ i < j ≤ N.



INPUT:

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. 

The first line of each description consists of a single integer N.

The second line of each description contains N space-separated integers - a1, a2, ..., aN respectively.



OUTPUT:
For each test case, output a single line containing a single integer - the smallest possible sum for the corresponding test case.



Test Case: 1

Input:

1
6
25 2 6 78 9 11
OUTPUT:
8                   

#include< iostream>

#include< bits/stdc++.h>

using namespace std;



int main()

{

    int T;

    cin>>T;

    while(T--)

    {

        int N;

        cin>>N;

        int a[N];

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

        {

            cin>>a[i];

        }

        sort(a , a+N);

        cout<< a[0]+a[1]<< endl;

    }

    return 0;

}                   






You are given a positive integer N. Your task is to print a solid rhombus of side N  with the help of stars.



INPUT:

First line of input contains T for test cases.

For each test case, the next line contains one integer indicating the value of side of rhombus.



OUTPUT:

Contains a pattern of given side.



Test Case: 1

INPUT:

1

 5



OUTPUT:

        *  *  *  *  * 

      *  *  *  *  * 

    *  *  *  *  * 

  *  *  *  *  * 

*  *  *  *  *                          

#include< iostream>

using namespace std;

int main()

{

    int T;

    cin >> T;

    while(T--)

    {

	int s;

	cin>>s;

	

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

	{

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

		{

			cout<<"  ";

		}

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

		{

			cout<<"* ";

		}

		cout<< endl;

	}

    }

	return 0;

}                          






You are given a string of lowercase characters(english alphabets) from ‘a’ – ‘z’. Your task is to write a program to print the characters of this string in sorted order.

Input:
The first line contains an integer T, denoting number of test cases. 

Then T test case follows. First line of each test case contains a string str each.

Output:
For each test case, print the string str in sorted order.


Test Case: 1
INPUT:
1

competitive



OUTPUT:
ceeiimopttv                     

#include< iostream>

#include< bits/stdc++.h>

using namespace std;

int main()

 {

	

	int T;

	cin >> T;

	while (T--)

	{

	    string str;

	    cin >> str;

	    

	    sort(str.begin(), str.end());

	    cout << str << endl;

	}

	return 0;

}                             






You are given an integer N. Your task is to find its square root.

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

Next Line contains T space separated integers indicating the values of N.

OUTPUT:
Contains T space separated integers indicating the values of squares roots for each value of N.



Test Case: 1

INPUT:

2

4 5

OUTPUT:

2 2 

Explanation :

The square root of 4 is 2 and the square root of 5 is 2.236 which is 2 in integer format.                    

#include < bits/stdc++.h>

using namespace std;

int main()

{

	int T;

	cin>>T;

	while(T--)

	{

	    int N;

	    cin>>N;

	    int ans = sqrt(N);

	    cout<< ans<<"  " ;

	}

	return 0;

}