Hi everyone!
I have a c program that will create a 2xm array, and my goal is to have the second row increment from zero to m and then have the first row copy the second row (i could increment the first row too, but for practice, i want to see if i can copy the data in the second row to the first row.
here is my code:
Code:
#include <stdlib.h>
#include <stdio.h>
int main(){
int s2 = 5;
int array[2][s2];
int j;
int i;
//initialize the first row to zeros
for(j = 0; j < s2 + 1; j++){
array[0][j] = 0;
}
//make the second row an increasing increment
for(j = 0; j < s2 + 1; j++){
array[1][j] = j;
}
//print out the 2m array
for(i = 0; i < 2; i++){
for(j = 0; j < s2 + 1; j++){
printf("%d\t", array[i][j]);
}
printf("\n");
}
printf("\n\n");
//copy the second row to the first row
for(j = 0; j < s2+1; j++){
array[0][j] = array[1][j];
}
//print out the 2m array
for(i = 0; i < 2; i++){
for(j = 0; j < s2 + 1; j++){
printf("%d\t", array[i][j]);
}
printf("\n");
}
return 0;
}
the data that i get is:
0 1 2 3 4 5
5 1 2 3 4 5
and i don't get why the first columns aren't the same..
i hard coded the m in 2xm for better reading..
any help is appreciated!!