Saturday, 18 June 2016

c code for pattern









































#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
char str[100];
    int i,j,len,spc,k;
    scanf("%s",str);
    len=strlen(str);
    spc=len;
    for(i=0,j=len-1;i<(len/2)&&j>(len/2);i++,j--){
        spc=spc-2;
        printf("%c",str[i]);
       for(k=1;k<=spc;k++)
            printf(" ");
        printf("%c\n",str[j]);
    }
   j++;
    i--;
    printf("%c\n",str[len/2]);
    for(;i>=0&&j<=len-1;i--,j++){
        printf("%c",str[i]);
        for(k=1;k<=spc;k++)
            printf(" ");
        printf("%c\n",str[j]);
        spc=spc+2;
    }
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    return 0;
}

No comments:

Post a Comment