Thanks for entering my thread. I am in an intro to programming class. Unfortunately for me, my instructor didn't manage his time well enough so we are rushing through the C programming sections that prepare us for part 2 of the class.
My assignment is to fill a 2-dimensional array with the values 1 - 20 in reverse order (descending) with loop commands.
This was the first one I came up with.
Code:
#include <stdio.h>
main()
{
int x;
int y;
int array[20][2];
for ( x = 0; x < 20; x++ ) {
array[x][1] = 20-x;
}
for ( x = 0; x < 20; x++ ) {
printf( "%d", array[x][1] );
printf( "\n" );
}
}
I made this next one with a nested loop. Also, this one doesn't have any empty array values like the previous one.
Code:
#include <stdio.h>
main()
{
int x;
int y;
int array[10][2];
for ( x = 0; x < 10; x++ )
{
for ( y = 0; y < 2; y++)
{
array[x][y] = 20-(2*x+y);
}
}
for ( x = 0; x < 10; x++ )
{
for ( y = 0; y < 2; y++)
{
printf( "%d ", array[x][y] );
}
printf( "\n" );
}
}
Am I on the right track?