===================Example1===================
// draws a (ugly) smiley face on the screen

// Demonstrates how to use two dimensional arrays

// Compile command for this code: (c version)
// gcc -Wall -W -Werror picture1.c -o picture1
// Compile command for this code: (c++ version)
// g++ -Wall -W -Werror picture1.c -o picture1

// For a good explanation of two-d arrays, see
// http://www.tutorialspoint.com/cprogramming/c_multi_dimensional_arrays.htm

#include<stdio.h>
#include<stdlib.h>
#include <unistd.h>
int main() {
int numbers[10][15];
int row;
int col;
int j;
for(j = 0; j<10; j++){
printf("\033[2J"); // Clear screen
printf("\033[1;1H"); // position the cursor at row 1, column 1
/* populate the array */
for(row = 0; row<10; row++){for (col=0; col <15; col++){numbers[row][col] = 0;}}
numbers[0][2] = 1; numbers[0][3] = 1; numbers[0][4] = 1; numbers[0][5] = 1;
numbers[1][1] = 1; numbers[1][6] = 1;
numbers[2][0] = 1; numbers[2][7] = 1;
numbers[4][2] = 1; numbers[4][5] = 1;
for(row = 9; row>-1; row--){
for(col=0; col <15; col++){
if (numbers[row][col]==0) printf(" ");
else printf("x");
}
printf("\n");
}
}
return(0);
}
===================Example2===================
// moving_x_upward.c

// Make an x move upward on the screen. x is step on space to the right each time.

// Compile command for this code, c version:
// gcc -Wall -W -Werror moving_x_upward.c -o moving_x_upward
// Compile command for this code, c++ version:
// g++ -Wall -W -Werror moving_x_upward.c -o moving_x_upward

// For a good explanation of two-d arrays, see
// http://www.tutorialspoint.com/cprogramming/c_multi_dimensional_arrays.htm

#include<stdio.h>
#include<stdlib.h>
#include <unistd.h>
int main() {
int numbers[10][15];
int row;
int col;
int j;
int k;
for(k = 0; k<15; k++){
for(j = 0; j<10; j++){
printf("\033[2J"); // Clear screen
printf("\033[1;1H"); // position the cursor at row 1, column 1
/* populate the array */
for(row = 0; row<10; row++){for (col=0; col <15; col++){numbers[row][col] = 0;}}
numbers[j][k] = 1;
for(row = 9; row>-1; row--){
for(col=0; col <15; col++){
if (numbers[row][col]==0) printf(" ");
else {printf("x");
}
}
printf("\n");
}
printf("\r");
fflush(stdout);
usleep(100000);
}
}
return(0);
}
===================Example2===================
// moving_x_upward_defs.c
// Make an x move upward on the screen. x is step on space to the right each time.

// Compile command for this code, c version:
// gcc -Wall -W -Werror moving_x_upward_defs.c -o moving_x_upward_defs
// Compile command for this code, c++ version:
// g++ -Wall -W -Werror moving_x_upward_defs.c -o moving_x_upward_defs

// For a good explanation of two-d arrays, see
// http://www.tutorialspoint.com/cprogramming/c_multi_dimensional_arrays.htm

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define nrows 15 // The compiler will replace "nrows" with "15" everhere in the program.
#define ncols 30
int main() {
int numbers[nrows][ncols];
int row;
int col;
int j;
int k;
for(k = 0; k<ncols; k++){
for(j = 0; j<nrows; j++){
printf("\033[2J"); // Clear screen
printf("\033[1;1H"); // position the cursor at row 1, column 1
/* populate the array */
for(row = 0; row<nrows; row++){for (col=0; col <ncols; col++){numbers[row][col] = 0;}}
numbers[j][k] = 1;
for(row = nrows-1; row>-1; row--){
for(col=0; col <ncols; col++){
if (numbers[row][col]==0) printf(" ");
else {printf("x");
}
}
printf("\n");
}
printf("\r");
fflush(stdout);
usleep(10000);
}
}
return(0);
}
===================Example3===================
// exploding_star.c
// Make an x move upward on the screen. x is step on space to the right each time.

// Compile command for this code, c version:
// gcc -Wall -W -Werror exploding_star.c -o exploding_star
// Compile command for this code, c++ version:
// g++ -Wall -W -Werror exploding_star.c -o exploding_star

// For a good explanation of two-d arrays, see
// http://www.tutorialspoint.com/cprogramming/c_multi_dimensional_arrays.htm

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define nrows 30 // The compiler will replace "nrows" with this number everywhere in the program.
#define ncols 30
int main() {
int a_now[nrows][ncols]; //What to display on the screen
int a_next[nrows][ncols]; //Used for computing the next display
int row;
int col;
int loop_num = 0;
// Start by filling the array with zeroes
for(col = 0; col<ncols; col++){for(row = 0; row<nrows; row++){a_now[row][col] = 0;a_next[row][col] = 0;}}
a_now[nrows/2][ncols/2]=1; //Put the very first * into the middle of a_now array. Its like a "seed".
for(loop_num = 0; loop_num<10; loop_num++) {
// Display the array data
printf("\033[2J"); // Clear screen
printf("\033[1;1H"); // position the cursor at row 1, column 1
for(row = nrows-1; row>-1; row--){
for(col=0; col <ncols; col++){
if (a_now[row][col]==0) printf(" "); // Print either a blank or a *
else printf("*");
}
printf("\n");
printf("\r");
}
fflush(stdout);
usleep(100000);
// Erase a_next, filling it with zeroes
for(row = 0; row<nrows; row++){for (col=0; col <ncols; col++){a_next[row][col] = 0;}}
// Compute a_next
for(row = 1; row<nrows-1; row++){
for (col=1; col <ncols-1; col++){
if (a_now[row][col]==1) {
a_next[row+1][col]=1; // up
a_next[row+1][col+1]=1; // up and right
a_next[row][col+1]=1; // right
a_next[row-1][col+1]=1; //down and right
a_next[row-1][col]=1; //down
a_next[row-1][col-1]=1; //down and left
a_next[row][col-1]=1; //left
a_next[row+1][col-1]=1; //left and up
}
}
}
// Move a_next to a_now
for(row = 0; row<nrows; row++){for (col=0; col <ncols; col++){a_now[row][col] = a_next[row][col];}}
} // end of the loop_num loop
return(0);
}




===================Example4===================
===================Example5===================