That's an interesting problem that a bunch of people seem to have right now. There are two ways to approach it:
The first way is to actually calculate the letter you wish to print out and use loops to do so, like so:
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX 5
int main ( void )
{
int i, j, x;
for ( i = 1, j = MAX; i < MAX, j > 0; i++, j-- ) {
for ( x = 0; x <= MAX; x++ ) {
if ( x == i || x == j )
printf ( "x" );
else
printf ( " " );
}
printf ( "\n" );
}
return EXIT_SUCCESS;
}
Another method is to place the required row and column coordinates in an array and use that to loop through and print your letter. This is the easiest way for complex letters and shapes.
Code:
#include <stdio.h>
#include <stdlib.h>
#define ROWS 5
#define COLS 5
int a[5][5] = { {3},{2,4},{1,2,3,4,5},{1,5},{1,5} };
int main ( void )
{
int x, y, z, flag = 0;
for ( x = 0; x < ROWS; x++ ) {
for ( y = 1; y <= COLS; y++ ) {
for ( z = 0; z < COLS; z++ ) {
if ( y == a[x][z] ) {
flag = 1;
break;
}
else
flag = 0;
}
if ( flag == 1 )
printf ( "a" );
else
printf ( " " );
}
printf ( "\n" );
}
return EXIT_SUCCESS;
}
-Prelude