C Code 10 _ To print the given string in a square pattern as shown below



C Code 10 _ To print the given string in a square pattern as shown below

Input : hello

Output:





Program:


#include<stdio.h>
#include<string.h>
int main()
{
    char str[20];
    int l,i,j,lll,ll;
    printf("enter a string : ");
    gets(str);
    l=strlen(str);
    ll=l;
    lll=l;
    ll=ll-2;
    lll=lll-2;
    for(i=0;i<l;i++)
    {
        for(j=0;j<l;j++)
        {
             if(i==0)
             {
                     printf("%c",str[j]);
             }
             else if(j==0)
             {
                    printf("%c",str[i]);
             }
             else if(j==l-1)
             {
                  printf("%c",str[ll]);
                  ll=ll-1;
             }
             else if(i==l-1)
             {
                  printf("%c",str[lll]);
                  lll=lll-1;;
             }
             else
             {
                 printf(" ");
             }           
        }
        printf("\n");
    }
    getch();
    return 0;
}




Output:








Thank You ...
Previous Post
Next Post
Related Posts

0 comments:

Popular Posts