Hello people i got a h.w to do Using nested loops to produce the following pattern:
F

FE

FED

FEDC

FEDCB

FEDCBA


I had idea to do it but that will require array and strlen(char first int of the outer loop) and the thing says that I must do it with char only
but here my code i made problem is that it need to intilise c='F' then its bigger than or = 'A' and i decrement it so it shows from F to A problem that there wont be any thing to intilise the inner loop to the outer integer or that may seem true to me maybe its wrong since i dont have much programming experience and i alawys sucks in nested loop anyways here code now

#include <stdio.h>
int main(void)
{
    int i,x;
    char c;
    for(i=0;i<6;i++) {
        for(c='F',x=i;c>='A' && x<=i;c-- , x++) {
            printf("%c ",c);
            }
        puts("");
        }
    return getchar();
}

as i think in inner loop i intilise c to f then c is bigger or = to a then i make x<=i whish will like first time 1 2 etc but shouldnt that also print
F then FE etc ? since x will be incremeted each time ?

Take the pattern out of it and do a simple triangle:

F
FF
FFF
FFFF
FFFFF
FFFFFF

You can add another variable that counts down without changing how the loops work in the triangle code:

for x = 1 to 6
    for y = 0 to x
        print 'F'
    print '\n'
for x = 1 to 6
    c = 'F'
    for y = 0 to x
        print c
        c = c - 1
    print '\n'

Try to take your problems and break them apart into smaller problems and you can see how to do things easier. :)

ohh thanks alot man i got it to work yah i will divide stuff into smaller stuff so i get the result in the end

#include <stdio.h>
int main(void)
{
    int i,x;
    char c;
    for(i=0;i<6;i++) {
        c='F';
        for( x=0 ; x<=i; x++ ) {
            printf("%c ",c);
            c--;
            }
        puts("");
        }
    return getchar();
}

problem that i did x=i; whish set x to the same num as i everytime the loop counts

return getchar();

I forgot to mention, but returning getchar() is a bad idea because it's never going to be 0, and a nonzero return from main means the program failed. The best three values for returning from main are 0 and EXIT_SUCCESS for success, or EXIT_FAILURE for failure. EXIT_SUCCESS and EXIT_FAILURE are defined in <stdlib.h>.

well thats just small program since i m coding that in dev but with big programs i code in other compilers like msv8 i return 0;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.