Create an array of size 5x5 first fill the array with random values between 1 and 100, print it in straight and reverse order. Then fill that array from the user, print it in straight and reverse order.
#include <iostream>
#include <ctime>
#include <stdlib.h>
using namespace std;
int main() {
const int line = 5;
const int col = 5;
int array[line][col] = {};
int i,j;
srand(time(NULL));
for( i=0; i<line; ++i)
for( j=0; j<col; ++j)
array[i][j] = rand()%100 + 1; // Random int range from 1 to 100[i][j];
cout<<endl<<"RAND:"<<endl;
for( i=0; i<line; ++i) {
for( j=0; j<col; ++j)
cout<<array[i][j]<<' ';
cout<<endl;
}
cout<<endl<<"RAND (revers):"<<endl;
for( i=line-1; i>=0; --i) {
for( j=col-1; j>=0; --j)
cout<<array[i][j]<<' ';
cout<<endl;
}
cout<<endl;
cout << "Enter 25 numbers:\n";
for( i=0; i<line; ++i)
for( j=0; j<col; ++j)
cin >> array[i][j];
cout<<endl<<"ARRAY:"<<endl;
for( i=0; i<line; ++i) {
for( j=0; j<col; ++j)
cout<<array[i][j]<<' ';
cout<<endl;
}
cout<<endl<<"ARRAY (revers):"<<endl;
for( i=line-1; i>=0; --i) {
for( j=col-1; j>=0; --j)
cout<<array[i][j]<<' ';
cout<<endl;
}
return 0;
}
Comments
Leave a comment