+ 2

So what am i doing wrong in the following pattern?

pattern:. A BAB CBABC DCBABCD https://code.sololearn.com/cZNC8KOHGsnP/?ref=app

11th Dec 2018, 2:26 PM
Abhay
Abhay - avatar
5 Réponses
+ 5
That's the most basic and inefficient way to draw a triangle. You should take your time and improve it. Basically, first and forth for loops (inside the outer loop) are responsible for space padding on both sides of the triangle. Second and third loops do necessary addition and subtraction (based on the current value of the outer loop index) to make up the letter sequence — one loop generate letters from left to the middle and other from middle + 1 to the right.
11th Dec 2018, 3:46 PM
Babak
Babak - avatar
+ 3
Possible Fix: #include <stdio.h> int main() { char a, b, k; int i, j; printf("enter a character:"); scanf("%c", &a); b = a; for (i = 5; i >= 1; i--) { for (j = i - 1; j >= 1; j--) printf(" "); for (k = (a + 5 - i) ; k >= b; k--) printf("%c", k); for (k = a + 1; k <= (b + 5 - i); k++) printf("%c", k); for (j = i - 1; j >= 1; j--) printf(" "); printf("\n"); } } Sample output: enter a character: A A BAB CBABC DCBABCD EDCBABCDE
11th Dec 2018, 2:57 PM
Babak
Babak - avatar
+ 1
ok that's confusing me ,you added two for statements for space and instead of increasing a,you added 5!
11th Dec 2018, 3:09 PM
Abhay
Abhay - avatar
0
If I am thinking right!
11th Dec 2018, 3:11 PM
Abhay
Abhay - avatar
0
ok I did some changes and its returning no output ,why?
11th Dec 2018, 8:16 PM
Abhay
Abhay - avatar