REVERSE PATTERN PROGRAM IN C++ USING NESTED LOOP WITH STRING.

#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;i++)
{
for(int j=0;j<=(n-1)*2;j++)
{
if(j<=i)
cout<<name[j];
else if(j>=(n-1)*2-i)
cout<<name[(n-1)*2-j];
else
cout<<"-";
}
cout<<endl;
}
getch();
}

/*Output of the above program..

N-------------N
NA-----------AN
NAR---------RAN
NARE-------ERAN
NAREN-----NERAN
NAREND---DNERAN
NARENDR-RDNERAN
NARENDRARDNERAN

*/
Powered by Blogger.