Code Program :
This file contains hidden or 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(); | |
} |
Silahkan berkomentar yang sesuai dengan topik, Terima Kasih.
EmoticonEmoticon