#Make a pattern with C

1 messages · Page 1 of 1 (latest)

cobalt spade
#

How to do this with for loops in C ?

wicked gulch
#

What have you got so far? Anything?

cobalt spade
languid spoke
#

What's your code?

woven ginkgo
#

Hmm, you'd need nested loops. And pay attention to special chars 👀 since i see $ sign there and not a letter

cobalt spade
#

#include<stdio.h>
int main(){
char fi, se;
int line, i, j, k;

printf("Enter 1st: ");
scanf(" %c", &fi);

printf("Enter 2nd: ");
scanf(" %c", &se);

printf("Enter lines: ");
scanf("%d", &line);

for(i = 0; i < line; i++){
    printf("%c", fi);
    for(j = 0; j < i; j++){
        printf("%c", se);
        for(k = 0; k < j; k++){
            printf("%c", fi);
        }
    }
    printf("\n");
}
return 0;

}

#

this my code

#

Any idea ?

woven ginkgo
#

And why declare variables used in loops at the top of main? X_X

cobalt spade
#

i figure it out