need following output in c++

Status
Not open for further replies.

QwertyManiac

Commander in Chief
I hate triangles. Why on earth do schools give so much of these crap as homework I'll never know. Loops can be learned in better ways!

Code:
#include <iostream>

using namespace std;

int main(void)
{
	int i(0),j(0),n(0);
	int index(1);
	cout<<"Enter no. of rows: ";
	cin>>n;
	for(i=1;i<n+1;i++)
	{
		for(j=1;j<n-i+1;j++)
		{
			cout<<" ";
		}
		for(j=1;j<i+1;j++)
		{
			cout<<i<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
	//End of Program 1
	for(i=0;i<n;i++)
	{
		//Weird space indent in 2nd right triangle. Still...
		for(j=0;j<5;j++)
		{
			cout<<" ";
		}
		for(j=0;j<i+1;j++)
		{
			cout<<(index%10);
			index++;
		}
		cout<<endl;
	}
	cout<<endl;
	//End of Program 2
	for(i=1;i<n+1;i++)
	{
		for(j=1;j<n-i+1;j++)
		{
			cout<<" ";
		}
		for(j=i;j>0;j--)
		{
			cout<<(j&1);
		}
		cout<<endl;
	}
	//End of Program 3, your second right angle.
	return 0;
}

And for your TurboCrap's (a.k.a Turbo C/C++) sake, just and another #include <conio.h> and a getch(); before return 0; at end. :|
 
Last edited:

QwertyManiac

Commander in Chief
You, in fact, have already done what you had said you won't do and you are still mostly oblivious to how this code functions and have just smacked it all down onto paper, ready for submission or to move along to the next chapter post memorizing it.

All this holds true with a P = 0.96.
 

QwertyManiac

Commander in Chief
No they never did give me those, but 0.85 of all these queries of "need program" are all mere homework or assignments of people.

Am glad to do something if I have the free time but its the OP at loss, as always.
 
Status
Not open for further replies.
Top Bottom