/****************************************************** * CP - I warmup 1999-2000 * Problem #9 *****************************************************/ /* * Question: * * You are required to write a program in C to generate a pattern * as shown below. * * * * $ * * # $ * * * # $ * * # $ * * $ * * * * * To generate the above pattern, you are required to take the * characters to be displayed as input from the user. The first * character would form the central symbol, the second would be the * symbol on the left side of the central symbol and so on. * * For the above pattern the input sequence would be *$#a. */ #include<stdio.h> #define MAX_LENGTH 20 main() { char str[MAX_LENGTH]; printf("Give the string: "); scanf("%s",str); pattern(str); } int pattern(char *str) { int i,j,len; len=strlen(str); for(i=0;i<2*len-1;i++) { for(j=len-1;j>=0;j--) { if(i<len) { if(i-j>=0) printf("%-4c",str[j]); else printf(" "); } else { if(i+j<2*len-1) printf("%-4c",str[j]); else printf(" "); } } printf("\n"); } }