Rabu, 26 November 2025

ex1008.c GRID forward backwards

/* ex1008.c */
#include <stdio.h>
#define GRID 3

/* prototype */
void forward(void);
void backwards(void);

int main()
{
    puts("Grid forward: ");
    forward();
    puts("Grid backwards: ");
    backwards();
    return(0);
}

void forward(void)
{
    int x,y;
    for(x=0;x<GRID;x++)
    {
        for(y=0;y<GRID;y++)
            printf("%d:%d\t",x,y);
        putchar('\n');
    }
}

void backwards(void)
{
    int x,y;
    for(x=GRID-1;x>=0;x--)
    {
        for(y=GRID-1;y>=0;y--)
            printf("%d:%d\t",x,y);
        putchar('\n');
    }
}

output:
 
Grid forward:
0:0     0:1     0:2
1:0     1:1     1:2
2:0     2:1     2:2
Grid backwards:
2:2     2:1     2:0
1:2     1:1     1:0
0:2     0:1     0:0

Process returned 0 (0x0)   execution time : 0.123 s
Press any key to continue.

Tidak ada komentar:

Posting Komentar