The program accepts two character inputs and construct a diamond out of them in this shape:
I'm working on the first half of the diamond, but I'm having trouble constructing the inner Bs, particularly the double increment in every row.Code:A ABA ABBBA ABBBBBA ABBBA ABA A
Code:#include <stdio.h> char info (void) { char x; printf("Insert a character: "); scanf("%c", &x); getchar(); return x; } void diamond (char a, char b) { int c1, c2, ch = 0, sp = 4, sp1, sp2; for (c1 = 0; c1 < 4; c1++, sp--, ch++) { for (sp1 = 0; sp1 < sp; sp1++) { printf(" "); } printf("%c", a); for (c2 = 0; (c2 < ch) && ((ch - c2) < 5); c2++, ch++) { printf("%c", b); } if (c1 == 0) { printf("\n"); } else { printf("%c\n", a); } } } int main (void) { char a, b; a = info (); b = info (); printf("\n"); diamond(a, b); printf("%c and %c", a, b); return 0;



LinkBack URL
About LinkBacks


