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.