FY_BCA_C_SLIP_5




/* Slip no : 5_1 write a C prog to accept a string from user and generate following pattern
   (eg input string is "abcd")
   a
   ab
   abc
   abcd
   abc
   ab
   a
 */

#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
                int i,j,n; char str[20];
                char ch;
                 clrscr();
                printf("\n enter string : ");
                scanf("%s",str);
                n=strlen(str);
                for(i=0;i<n;i++)
                {
                                for(j=0;j<=i;j++)
                                {
                                                printf("%c\t",str[j]);
                                }
                                printf("\n");
                }

for(i=n-1;i>=1;i--)
                {
                                for(j=0;j<i;j++)
                                {
                                                printf("%c\t",str[j]);
                                }
                                printf("\n");
                }
                getch();
}

No comments:

Post a Comment