CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;
int main()
{
int i,j,k,n;
int s=0;
cout<<"enter the number:";
cin>>n;
cout<<"\n";
for(i=1;i<=n;i++)
{
for(j=1;j<=(n-i);j++)
cout<<" ";
for(k=1;k<=i;k++)
{
cout<<k<<" ";
s+=k;
}
cout<<"\n";
}
cout<<"sum of triangle="<<s;
return 0;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run