number triangle c++ code example

Example 1: number triangle c++

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

Example 2: number triangle in c++

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n-i;j++)
		{
			cout<<" ";
		}
		for(int j=1;j<=i;j++)
		{
			cout<<j<<" ";
		}
		cout<<endl;
	}
	return 0;			
}

Example 3: number triangle c++

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;	
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(j<=n-i)
			{
				cout<<" ";
			}else{
				cout<<"*";
			}
			
		}cout<<endl;
	}
}

Tags:

Cpp Example