Wipro - C & C++ Coding Ability

Test Number 8


You are given the side of the rhombus. Your task is to print the hollow rhombus 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 sides of the rhombus.



OUTPUT:

Contains a pattern of given side.



Test Case: 1

INPUT:

1

5

OUTPUT:

        *  *  *  *  * 

      *              * 

    *              * 

  *              * 

*  *  *  *  *                 

#include

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++)

		{

			if(i==1 || i==s ||j==1 || j==s)

			{

				cout<<"* ";

			}

			else

			{

				cout<<"  ";

			}

		}

		cout<< endl;

	}

    }

	return 0;

}               






You are given a positive integer N. Your task is to check if the number is divisible by 7 then increment the number by 1, if not then decrement the number by 1.

INPUT:
First line of the input contains N.



OUTPUT:
Contains the final answer.



Examples:

Test Case: 1

INPUT:

14

OUTPUT:
15



Test Case: 2

INPUT:
18

OUTPUT:
17                   

#include 

using namespace std;



int main() {

	    int N;

	    cin >> N;

	    if(N%7==0)

	    {

	        N++;

	    }

	    else

	    {

	       N--;

	    }

	    cout << N;

	return 0;

}

                   






You are given a positive integer N. Your task is to draw an inverted pyramid pattern using integers 1 to N.

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:
1 1 1 1 1

2 2 2 2

3 3 3

4 4

5                          

#include

using namespace std;

int main()

{

    int T;

    cin >> T;

    while(T--)

    {

	int n;

	cin>>n;

	

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

	{

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

		{

			cout<< i <<" ";

		}

		cout<< endl;

	}

    }

	return 0;

}                          






You are given a positive integer N. Your task is to make an inverted half pyramid using these N numbers.

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:

1 2 3 4 5 

1 2 3 4 

1 2 3 

1 2 

1

                     

#include

using namespace std;

int main()

{

    int T;

    cin >> T;

    while(T--)

    {

	int n;

	cin>>n;

	

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

	{

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

		{

			cout<< j <<" ";

		}

		cout<< endl;

	}

    }

	return 0;

}                             






You are given the height of a pyramid. Your task is to print the inverted half pyramid 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=h; i>=1; i--)

	{

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

		{

			cout<<"* ";

		}

		cout<< endl;

	}

    }



	return 0;

}