Answer to Question #346455 in C++ for Ali

Question #346455

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.

1
Expert's answer
2022-05-30T15:13:59-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS