STRING PATTERN USING NESTED LOOP IN C++

#include<iostream.h>
#include<conio.h>
#include<string.h>

void main()
{
char name[]="NARENDRA";
int n;
clrscr();
n=strlen(name);
for(int i=0;i<n*2-1;i++)
{
for(int j=0;j<n;j++)
{
if(j<=i && i<n || j<=(n-1)*2-i && i>=n)
cout<<name[j];
else
cout<<" ";
}
cout<<endl;
}
getch();
}

/*Output of the above program..

N
NA
NAR
NARE
NAREN
NAREND
NARENDR
NARENDRA
NARENDR
NAREND
NAREN
NARE
NAR
NA
N


*/
Powered by Blogger.