Senin, 14 Mei 2012

Mencari Array Diagonal

share


# include <iostream.h>
# include <conio.h>

void main ()
{
  int nums[10][10]={1,2,3,4,5,6,7,8,9,10,
  21,22,23,24,25,26,27,28,29,30,
  51,52,53,54,55,56,57,58,59,60,
  101,102,103,104,105,106,107,108,109,110,
  121,122,123,124,125,126,127,128,129,130,
  31,32,33,34,35,36,37,38,39,40,
  41,42,43,44,45,46,47,48,49,50,
  81,82,83,84,85,86,87,88,89,90,
  151,152,153,154,155,156,157,158,159,160,
  91,92,93,94,95,96,97,98,99,100};
  int x, y, z, a, b, c ;
  clrscr () ;
  for (x=0 ; x<10 ; x++)
  {
                  for (y=0 ; y<10 ; y++)
                  {
                                  cout << nums[x][y] ;
                  }
                  cout << endl ;
  }
  a = 0 ;
  b = 0 ;
  c = 0 ;
  while (a<10)
  {
                  cout << nums[b][c] << "  " ;
                  a++ ;
                  b++ ;
                  c++ ;
  }
  cout << endl ;

  a = 0 ;
  b = 0 ;
  c = 9 ;
  while (a<10)
  {
                  cout << nums[b][c] << "  " ;
                  a++ ;
                  b++ ;
                  c-- ;
  }
}

Tidak ada komentar:

Posting Komentar