----------------------------------------------------------------------------------------------------- String Pyramid Try It
-----------------------------------------------------------------------------------------------------
#include<iostream>
#include<string.h>
using
namespace std;
int main()
{
string text
;
char
c[1024];
cout<<"Enter
a String : ";
cin>>text;
strncpy(c,
text.c_str(),sizeof(c));
c[sizeof(c)-1]=0;
for
(unsigned int i = 0; c[i]!=0 ;++i)
{
cout
<< '[' << i << "] == '" << c[i] <<
"'\n";
}
int
i,j,n,num=1,space;
cout<<"Enter how many rows u want : ";
cout<<"Enter how many rows u want : ";
cin>>n;
space=n-1;
for(i=0;i<n;i++)
{
num=i;
for(j=0;j<space;j++)
{
cout<<"
";
}
space--;
for(j=0;j<=i;j++)
{
cout<<c[num];
num++;
}
num--;
num--;
for(j=0;j<i;j++)
{
cout<<c[num];
num--;
}
}
cout<<"\n";
}
return 0;
}
-----------------------------------------------------------------------------------------------------
OUTPUT Try It
-----------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------
Enter a String : sunil
[0] == 's'
[1] == 'u'
[2] == 'n'
[3] == 'i'
[4] == 'l'
Enter hoe many rows u want : 3
s
unu
nilin