I am having problem understanding nested loops, esp in making patterns with them.
I am able to understand simple loops like these:
ABCDEFGHIJ
ABCDEFGHIJ
ABCDEFGHIJ
ABCDEFGHIJ
ABCDEFGHIJ
ABCDEFGHIJ
code for this will be:
#include <stdio.h>
#define ROWS 6
#define CHARS 10
int main(void)
{
int row;
char ch;
for (row = 0; row < ROWS; row++) /* line 10 */
{
for (ch = 'A'; ch < ('A' + CHARS); ch++) /* line 12 */
printf("%c", ch);
printf("\n");
}
return 0;
}
In this one the outer loop controls the no. of columns and the inner one control the no. of rows and data to be printed.
But I can't get my head around these kind of patterns:
$
$$
$$$
$$$$
$$$$$
OR
F
FE
FED
FEDC
FEDCB
FEDCBA
OR
A
ABA
ABCBA
ABCDCDA
ABCDEDCBA
Can someone please guide me? I need an explanation not just code.