Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Fill a 40x40 array with random numbers, 0 through 9. Don’t use or srand in your

ID: 3827574 • Letter: F

Question

Fill a 40x40 array with random numbers, 0 through 9. Don’t use or srand in your program. Print out the array or, at least the portion that appears in your output. Your numbers will be different than the ones shown below. (Note: you may not be able to see the whole array, it doesn't matter, make a graphic of whatever appears.) Then output the sum along both diagonals of the array. Your sums may be different than the ones shown below. 15 points for upper left to lower right diagonal; 10 points for lower left to upper right diagonal.

C++

Explanation / Answer


# include <iostream.h>
# include <conio.h>


void main()
{
   
  
       int i, j, r = 0, c = 0;
       int a [ 10 ][ 10 ];
       clrscr();

  
       cout << " Enter Number Of Rows & Columns Of 2D Array [ Matrix ] : ";
       cin >> r >> c ;
       
  
       cout << " Enter " << r * c << " Values for 2D Array :  ";
       for ( i = 0; i < r; i++ )
       {
                for ( j = 0; j < c; j++ )
                {
                         cin >> a [ i ][ j ];
                }
       }


       cout << " Values Of 2D Array [ Matrix ] Are : ";
       for ( i = 0; i < r; i++ )
       {
                cout << " ";
                for ( j = 0; j < c; j++ )
                {
                         cout << a [ i ][ j ];
                }
       }
sum=0;
if(r==c)
{
   for(i=0; i<r; i++)
   {
      for(j=0; j<c; j++)
      {
         if(i+j==0 || i+j==2 || i+j==4)
         {
            sum=sum+a[i][j];
         }
      }
   }

   cout<<" Sum Of Diagonal Elements Of Array Is : "<<sum;
}
else
{
   cout<<" Addition Is Not Possible";
}
getch();
}

Output :

Enter Order For Array A : 3 3

Enter 9 Values For Array :
1 2 3 4 5 6 7 8 9

Array A Is :
1 2 3
4 5 6
7 8 9

Sum Of Diagonal Elements Of Array Is : 15

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote