Ceriwis  

Go Back   Ceriwis > HOBI > Komputer & Teknologi > Programming

Programming Share, tanya jawab, saling bantu antar programmer dengan berbagai macam bahasa pemrograman.

Reply
 
Thread Tools
  #1  
Old 20th November 2011
JagoVB JagoVB is offline
Ceriwiser
 
Join Date: Nov 2011
Posts: 508
Rep Power: 14
JagoVB mempunyai hidup yang Normal
Default <ASK> Cara convert array 2D ke 1D di C

Saya punya masalah ketika mau convert array dari 2D ke 1D.

Ilustrasinya : array[3][3]={

{1, 2, 3},

{4, 5, 6},

{7, 8, 9}

}



mau saya ubah menjadi array[9]={1,2,3,4,5,6,7,8,9}



Kode saya sejauh ini :




Code:

#include
#include
#define NROWS 3
#define NCOLS 3

int getIndex(int row, int col)
{

int array[NROWS][NCOLS] ={
{'1','2','3'},
{'4','5','6'},
{'7','8','9'}
};

return row*NCOLS+col;
}

int main (int argc, char *argv[])
{
int i;
int j;
//int array_copy[MAX];

int myArr[NROWS*NCOLS];


for (i=0; i

Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


 


All times are GMT +7. The time now is 10:59 AM.


no new posts