Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- #include<time.h>
- #include<iostream>
- using namespace std;
- int random2digit(int max,int min);
- void printarr(int [5][5],int row,int col);
- int main()
- {
- srand(time(NULL));
- int A[5][5], row, col;
- do{
- cout << "Masukkan jumlah baris(1-5) ";
- cin >> row;
- if(row > 5 || row < 1)
- {
- cout << "Error!" << endl;
- }
- }while(row > 5 || row < 1);
- do{
- cout << "Masukkan jumlah kolom(1-5) ";
- cin >> col;
- if(col > 5 || col < 1)
- {
- cout << "Error!" << endl;
- }
- }while(col > 5 || col < 1);
- for(int i = 0; i < row; i++)
- {
- for(int j = 0; j < col; j++)
- {
- if(i%2 == 0)
- {
- A[i][j] = 2 * random2digit(49,0) + 1;
- }
- else
- {
- A[i][j] = 2 * random2digit(49,0);
- }
- }
- }
- printarr(A, row, col);
- return 0;
- }
- int random2digit(int max,int min)
- {
- int x;
- x = rand()%(max - min) + min;
- return (x);
- }
- void printarr(int A[5][5], int row,int col)
- {
- for(int i = 0; i < row; i++)
- {
- for(int j = 0; j < col; j++)
- {
- cout << A[i][j] << " ";
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement