Wipro - C & C++ Coding Ability

Test Number 7


You are given the height of a pyramid. Your task is to print the half pyramid with space with the help of stars. 



INPUT:

First line of input contains T for test cases.

For each test case, the next line contains an integer indicating the value of the height of the pyramid.



OUTPUT:

Contains a pattern of the given height.



Test Case: 1

INPUT:

1

 5



OUTPUT:

* 

*  * 

*  *  * 

*  *  *  * 

*  *  *  *  *                

#include

using namespace std;

int main()

{

    int T;

    cin >> T;

    while(T--)

    {

        int h;

        cin>>h;

	

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

	    {

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

		    {

			    cout<<"* ";

		    }

		    cout<< endl;

	    }

    }

    

	return 0;

}               






You are given the height of a pyramid. Your task is to print the half pyramid with 180-degree rotation with the help of stars. 

INPUT:

First line of input contains T for test cases.

For each test case, the next line contains an integer indicating the value of the height of the pyramid.

OUTPUT:

Contains a pattern of the given height.



Test Case: 1

INPUT:

1

5

OUTPUT:

                 *

             *  *

         *  *  * 

     *  *  *  *

 *  *  *  *  *                   

#include< iostream>

using namespace std;

int main()

{

    int T;

    cin >> T;

    while(T--)

    {

        int h;

	    cin>>h;

	

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

	    {

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

            {

        	    if(j<=h-i)

        	    {

        		    cout<<"  ";

			    }

			    else cout <<" *";

		    }

		    cout<< endl;

	    }

    }

	return 0;

}                   






Your task is to find the factorial of two numbers.

Input:

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

For each test case, next line containing two space-separated integers for which you have to find HCF.

Output:

Containing an integer which is the HCF of given numbers.                          

# include < iostream>

using namespace std;

int main()

{

	int T;

	cin >> T;

	while(T--)

	{

	int m,n;

	cin>>m>>n;

	while(m!=n)

    {

	   if(m>n)

	      m=m-n;

	else if(n>m)

	   n=n-m;

    }

    cout<< m<< endl;

	}

    return 0;



}                          






Write a code that prints "Hello World" on the screen (without quotation marks) with the help of the class.                     

                             

#include using namespace std; class Solution{ public: void helloWorld() { cout << "Hello World"; } }; int main() { Solution word; word.helloWorld(); cout << endl; return 0; }






You are given the height of a pyramid. Your task is to print the hollow pyramid pattern with the help of stars. 



INPUT:

The first line contains an integer indicating the value of the height of the pyramid.



OUTPUT:

Contains a pattern of the given height.



Test Case: 1

INPUT:
5


OUTPUT:

       *

    *    *

   *      *

  *         *

 *********                    

#include 

using namespace std;

int main()

{

    int h;

    cin>>h;

    

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

	{

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

		{ 

        cout<<" ";

        }

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

    {

            if(i==h || (j==1 || j==2*i-1))

            {

                cout<<"*";

            }

            else cout<<" ";

    }

    cout<< endl;

    }

    return 0;

}