Latihan Array 2 Dimensi

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

LATIHAN ARRAY 2 DIMENSI BUATLAH ANALISA DARI STRUKTUR PROGRAM INI:

FILE KIRIM KE E-MAIL DENGAN SUBJECT:

LATIHAN ARRAY 2D_NIM_NAMA_KLS

#include <iostream.h>

#include <conio.h>

int main()

char nama[100][100];

int nilai[100];

int no;

cout<<"masukkan jumlah mahasiswa: ";

cin>>no;

//input data

for (int i=1;i<=no;i++){

cout<<"masukkan nama mahasiswa: ";

cin>>nama[i];

cout<<"masukkan nilai mahasiswa: ";

cin>>nilai[i];

//menampilkan data

cout<<"tampilkan data"<<endl;

for (int a=1;a<=no;a++){

cout<<"nama: "<<nama[a]<<" dengan nilai: "<<nilai[a]<<endl;

getch();

}
PART 2
#include <stdio.h>
 
int main(void)
{
  int bilangan[2][2];
 
  bilangan[0][0] = 100;
  bilangan[0][1] = 101;
  bilangan[1][0] = 110;
  bilangan[1][1] = 111;
 
  printf("Isi array bilangan: \n");
  printf("%d, %d \n",bilangan[0][0],bilangan[0][1]);
  printf("%d, %d \n",bilangan[1][0],bilangan[1][1]);
 
  return 0;
}

PART 3
#include <stdio.h>
 
int main(void)
{
  int matrix[2][3] = {{1,2,3},{7,8,9}};
 
  printf("Isi array matrix: \n");
  printf("%d %d %d \n", matrix[0][0], matrix[0][1], matrix[0][2]);
  printf("%d %d %d \n", matrix[1][0], matrix[1][1], matrix[1][2]);
 
  return 0;
}

PART 4

#include <iostream.h>

#include <conio.h>

int main(){

int x,y,a[3][4],b[3][4];

cout<<"## Matrix 1 ##"<<endl;

for (x=0;x<=2;x++){

for (y=0;y<=3;y++){

cout<<"Masukkan Index ("<<x<<","<<y<<") = ";


cin>>a[x][y];

cout<<endl<<"## Matrix 2 ##"<<endl;

for (x=0;x<=2;x++){

for (y=0;y<=3;y++){

cout<<"Masukkan Index 2 ("<<x<<","<<y<<") = ";

cin>>b[x][y];

cout<<endl<<"## Matrix 1 + Matrix 2 ##"<<endl;

for (x=0;x<=2;x++){

cout<<endl;

for (y=0;y<=3;y++){

cout<<a[x][y]+b[x][y]<<" ";

getch();

PART 5

#include <iostream.h>

#include <conio.h>

int main()

int i, j, m, n, matriks1[10][10], matriks2[10][10], hasil[10][10];

cout << "Masukkan jumlah baris matriks: ";

cin >> m;

cout << "Masukkan jumlah kolom matriks: ";

cin >> n;

cout << "Masukkan elemen matriks pertama: \n";


for(i = 0; i < m; i++){

for(j = 0; j < n; j++){

cin >> matriks1[i][j];

cout << "Masukkan elemen matriks kedua: \n";

for(i = 0; i < m; i++){

for(j = 0; j < n; j++){

cin >> matriks2[i][j];

cout << "Hasil pengurangan matriks: \n";

for(i = 0; i < m; i++){

for(j = 0; j < n; j++){

hasil[i][j] = matriks1[i][j] - matriks2[i][j];

cout << hasil[i][j] << "\t";

cout << endl;

getch();

You might also like