Exercise #1
So, we've seen something useful in the mathematical sense concerning
using 2D arrays. Let's practice with 2D arrays by creating a
program of your own according to the following specifications :
- Your program should allow the user to type in a 3x3 matrix which
is to be stored in a 2D array of integers.
- The program should then calculate the determinant of this
3x3 matrix and print out both the matrix and its determinant.
Consider the following 3x3 matrix :
The deternimant, d, is d = aei + bfg + cdh - afh - bdi - ceg
Exercise #2
Here's your first animation exercise!
- Make two 2-D arrays that have a smiley face like so:
- Make two functions that contain each 2-D array and displays it.
- Have main() call each function repeatedly, 10 times, it will look
like the smiley face is winking!
- Feel free to be creative and use other characters instead of '#'
to give the face a "smooth" look.
Hints:
- Use the commmand:
to clear the screen for you
so that the picture appears in the same place each time.
NOTE: to use the system call you must first: #include
<stdlib.h>
- Use the commmand:
To make the computer pause for one second (if your picture blinks too fast)
- To save yourself some work declare the 2-D array like this example:
char cross[3][3] =
{ 'T', 'T', 'T',
' ', 'T', ' ',
' ', 'T', ' ' };
This inserts the spaces and 'T' in the corresponding spots. You can
only do this when you first declare the array.
- Be patient. You will find that any graphics program will require
a lot of repetitive work and fixing small details.