To generate the pattern using string function
String : jack
Patternj
ja
jac
jack
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[50];
int i,j,n;
clrscr();
printf("\nEnter the string :");
gets(str);
/*calculate the length of the string */
n=strlen(str)-1;
for(i=1;i<=n;i++)
{
for(j=0;j<i;j++)
{
printf("%c",str[j]);
}
printf("\n");
}
getch();
}
Comments
Post a Comment