C Code 8 _ Zoho Programming round question on patterns



C Code 8 _  Zoho Programming round question on patterns



To print the pattern as follows for the given string . the input string should be of odd number of characters.

example:

Input : hello

Output: 








Program :


#include<stdio.h>
#include<string.h>
int main()
{
    char str[50],srev[50];
    int l,mid,i,k=0,m,p,b,j;
    printf("Enter a Name : ");
    gets(str);
    l=strlen(str);
    m=l-1;
    if(l%2==1)
    {
        mid=(l/2);
        for(i=mid;i<l;i++)
        {
            srev[k]=str[i];
            k=k+1;
        }
        for(i=0;i<mid;i++)
        {
            srev[k]=str[i];
            k=k+1;
        }
        //puts(srev);
        for(i=0;i<l;i++)
        {
             b=0;
             for(j=0;j<l;j++)
             {
                  if(j>=m)
                  {
                          printf("%c",srev[b]);
                          b=b+1;
                  }
                  else
                  {
                          printf(" ");
                  }
             }
             printf("\n");
             m=m-1;
        }
    }
    else
    {
        printf(" Please ... Enter a Name of odd length( i.e, length of name should be a odd number). "); 
    }
    getch();
    return 0;
}



Output:








Thank you ...

Popular Posts