DIGIT-ARC read-only archive · snapshot: July 23, 2026

need following output in c++

8 posts · originally from https://geek.digit.in/community/threads/need-following-output-in-c.82848/

QwertyManiac
Mar 16, 2008 at 11:24 PM
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. :|
bhushan2k
Mar 16, 2008 at 11:53 PM
thnx man.....u r gr8.....never forget ur hlp.....
QwertyManiac
Mar 17, 2008 at 12:17 AM
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.
radonryder
Mar 20, 2008 at 5:16 PM
@QwertyManiac
They give you guys comp homework????
QwertyManiac
Mar 20, 2008 at 6:33 PM
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.
M
Mar 20, 2008 at 7:38 PM
And you learn more of probability, side by side.