Tuesday, 7 April 2015

C Program to print the following pattern :

a
a    b
a    b    c
a    b
a


#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
int i,j,len;
char str[50];
clrscr();
printf("Enter a string : \n");
scanf("%s",str);
len=strlen(str);
for(i=0;i<len;i++)
{
for(j=0;j<=i;j++)
{
printf("%c",str[j]);
}
printf("\n");
}
for(i=0;i<len;i++)
{
for(j=0;j<len-i-1;j++)
{
printf("%c",str[j]);
}
printf("\n");
}
getch();
}

No comments:

Post a Comment