Last active
May 11, 2017 07:14
-
-
Save fakhrikmt/e9bd5e0a04da668e3f9a6753e6434b48 to your computer and use it in GitHub Desktop.
Belajar C++ Array 2 Dimensi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream.h> | |
#include <conio.h> | |
#include <stdlib.h> | |
#include <iomanip.h> | |
int main(void) | |
{ | |
int matrix[10][10]; | |
int tampung[10]; | |
randomize(); | |
for(int i=0;i<10;i++) | |
for(int j=0;j<10;j++) | |
matrix[i][j]=random(20); | |
for(int i=0;i<10;i++) | |
{ | |
for(int j=0;j<10;j++) | |
cout<<setw(5)<<matrix[i][j]; | |
cout<<endl; | |
} | |
int x=0; | |
//menampung baris ke-0... | |
for(int b=0;b<10;b++) | |
{ | |
for(int i=0;i<10;i++) | |
for(int j=0;j<10;j++) | |
if(j==b) | |
{ | |
tampung[x]=matrix[i][j]; | |
x++; | |
} | |
//mengurutkan nilai di tampung | |
int tamp; | |
for(int i=0;i<10;i++) | |
for(int j=0;j<10;j++) | |
if(tampung[i]<tampung[j]) | |
{ | |
tamp=tampung[i]; | |
tampung[i]=tampung[j]; | |
tampung[j]=tamp; | |
} | |
int a=0; | |
for(int i=0;i<10;i++) | |
for(int j=0;j<10;j++) | |
if(j==b) | |
{ | |
matrix[i][j]=tampung[a]; | |
a++; | |
} | |
a=0;x=0; | |
} | |
//endfor | |
cout<<"\nMatrix setelah diurutkan perbaris adalah:\n"; | |
for(int i=0;i<10;i++) | |
{ | |
for(int j=0;j<10;j++) | |
cout<<setw(5)<<matrix[j][i]; | |
cout<<endl; | |
} | |
getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment