Space Pattern Program in C

  • by

These code demostrate how to create space pattern program in c, c++, java etc. language.
#include<stdio.h>
#include<string.h>
int main()
{

char str[]="prog";
int i,j,k,len,l;
int sp=0;
len=strlen(str);
for(i=1;i<=len;i++)
{
for(j=0;j<=len-i;j++)
{

printf("%c",str[j]);

}

for(l=0;l<sp;l++)
{
printf(" ");

}
if(sp==0)
{
sp=1;
}

else

{
sp=sp+2;
}

for(k=len-i;k>=0;k- -)
{
if(k==len)
{

}

else

{
printf("%c",str[k]);
}
}
printf("\n");
}
}

Outout Pattern -:
progorp
pro  orp
pr      rp
p         p

Leave a Reply