How to write a c program to accept a string from user & generate following pattern (e.g, input "abcd") in C Programming Language ?
Solution:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char c[20];
int i,j,len;
clrscr();
printf("\nEnter the string: ");
gets(c);
len=strlen(c);
for(i=0;i<len;i++)
{
for(j=0;j<=i;j++)
{
printf("%c",c[j]);
}
printf("\n");
}
for(i=len-1;i>0;i--)
{
for(j=0;j<i;j++)
{
printf("%c",c[j]);
}
printf("\n");
}
getch();
}
//OUTPUT:
//Enter the string: abcd
a
ab
abc
abcd
abc
ab
a