Friday, February 20, 2015

Arry 2 Dimensi



Arry 2 Dimensi
 
/* Program array berdimensi dua */
#include <conio.h>
#include <stdio.h>
#include <iostream.h>
#include <iomanip.h>
void main() {
      int i,j;
   int data_jual[3] [4];
   char nma[3] [5]= {" "};

   for (i=1; i<=3; i++) {
   cout<<"Merek sepeda motor : "; cin>>nma [i-1][i];
     for (j=1; j<=3; j++) {
           cout << "Data ke-"<<i<<" "<<j<< endl;
         cout << "Jumlah Penjualan: "; cin >> data_jual[i-1] [j];
      }
   }
      cout << "Data Penjualan Per Tahun" << endl;
   cout << "      Sepeda Motor      " << endl;
   cout << "======================================" << endl;
   cout << "No   Nama motor   2004   2005    " << endl;
   cout << "======================================" << endl;
   for (i=1; i<=3; i++) {
     cout << setiosflags(ios::left) << setw(5) << i;
      cout << nma[i-1][i];
      for (j=1; j<=3; j++) {
           cout << setiosflags(ios::right) << setw(4);
         cout << data_jual[i-1] [j];
         cout << "    ";
      }
      cout << endl;
   }
   cout << "======================================" << endl;
   getch();
}


/* Program array berdimensi dua */
#include <conio.h>
#include <stdio.h>
#include <iostream.h>
#include <iomanip.h>
void main() {
     int i,j;
   int data_jual[3] [3];

   for (i=0; i<=2; i++) {
     for (j=0; j<=2; j++) {
           cout << "Data ke-"<<i<<" "<<j<< endl;
         cout << "Jumlah Penjualan: "; cin >> data_jual[i] [j];
      }
   }
      cout <<" Data Penjualan Tahun" << endl;
   cout << "      Sepeda Motor   " << endl;
   cout << "=====================" << endl;
   cout << "No   2004 2005 2006  " << endl;
   cout << "=====================" << endl;
   for (i=0; i<=2; i++) {
     cout << setiosflags(ios::left) << setw(5) << i;
      for (j=0; j<=2; j++) {
           cout << setiosflags(ios::right) << setw(4);
         cout << data_jual[i] [j];
      }
      cout << endl;
   }
   cout << "======================" << endl;
   getch();
}

No comments:

Post a Comment