Write a ‘C’ program to accept a string from user, generate following pattern (e.g. input is string “abcd”)

#include<stdio.h>
#include<conio.h>
void main()
{
char name[20];
int x,y;
clrscr();
printf("\n enter any string :");
scanf("%s",name);
printf("\n enter the name :%s",name);
x=0;
while(x<=strlen(name))
{
printf("\n");
for(y=0;y<x;y++)
{
printf("%c",name[y]);
}
x++;
}
x=strlen(name);
while(x>=0)
{
printf("\n");
for(y=0;y<x-1;y++)
{
printf("%c",name[y]);
}
x--;
}
getch();
}

Comments

Post a Comment