If you like the answer, please give a Thumps up.
Kindly comment, if you need any modifications.
The required statements are
for(int i=0;i<ROWSIZE;i++)
{
for(int j=0;j<COLSIZE;j++)
{
if(play1[i][j]==play2[i][j])
tricky+=play1[i][j];/
else
tricky+=play1[i][j]+play2[i][j];
}
}
cout<<"Tricky ="<<tricky<<endl;
Complete Program
#include<iostream>
using namespace std;
//Declare two integer constants ROWSIZE equal to 4 and COLSIZE
equal to 4.
#define ROWSIZE 4
#define COLSIZE 4
int main()
{
//Declare and initialize two two‐dimensional
arrays,play1 and play2
int
play1[ROWSIZE][COLSIZE]={{1,5,3,7},{6,8,5,8},{3,3,3,5},{7,8,1,5}};
int
play2[ROWSIZE][COLSIZE]={{4,6,3,7},{5,0,7,8},{8,7,6,5},{7,3,4,5}};
//Declare and initialize variable tricky to 0
int tricky=0;
//Each row of play1 is compared element by element
to the corresponding row of play2
//If the elements are equal, add the value of one
element to tricky
//If the elements are not equal, add the sum of the
two elements to the value of trıcky
for(int i=0;i<ROWSIZE;i++)
{
for(int j=0;j<COLSIZE;j++)
{
if(play1[i][j]==play2[i][j])
tricky+=play1[i][j];//If the elements are equal,
add the value of one element to tricky
else
tricky+=play1[i][j]+play2[i][j];//If the
elements are not equal, add the sum of the two elements to the
value of trıcky
}
}
cout<<"Tricky
="<<tricky<<endl;
}
Program Screenshot
Output
Tricky =128
QUESTION 4 16 marks 4.1 4.2 (4) (4) Declare two integer constants RONGI ZE equal to...
QUESTION 4 16 marks 4.1 4.2 (4) (4) Declare two integer constants RONGI ZE equal to 4 and Ca.SI ZEequal to 4. Declare two i nt two-dimensional arrays, namely playlwith ROWI ZEnumber of rows and COLSI ZEnumber of columns, and play2with RONGI ZEnumber of rows and COLSI ZEnumber of columns, 4.3 Assume that values have been assigned to all the elements of pl ayland play 2. Also assume that ani nt variable trickyhas been declared and intialised to 0. Use...
QUESTION 4 16 marks 4.1 4.2 Declare two integer constants ROWI ZE equal to 4 and CO.SI ZEequal to 4. (4) Declare two i nt two-dimensional arrays, namely (4) playlwith ROMSI ZEnumber of rows and COL SI ZE number of columns, and pl ay2 with ROMI ZEnumber of rows and COL SI ZEnumber of columns, 4.3 Assume that values have been assigned to all the elements of pl ayland play. Also assume that ani nt variable tricky has been declared...
QUESTION 4 16 marks 4.1 4.2 Declare two integer constants ROWSIZE equal to 4 and COLSIZEequal to 4. Declare two inttwo-dimensional arrays, namely playlwith ROWSIZEnumber of rows and COLSIZEnumber of columns, and play with ROWSIZEnumber of rows and COLSIZEnumber of columns, (4) (4) 4.3 Assume that values have been assigned to all the elements of playland play. Also assume that an int variable trickyhas been declared and intialised to 0. Use nested forloops and write down the necessary C++ statements...
4.1 4.2 (4) (4) Declare two integer constants ROWSIZE equal to 4 and COLSIZEequal to 4. Declare two inttwo-dimensional arrays, namely playlwith ROWSIZEnumber of rows and COLSIZEnumber of columns, and play2with ROWSIZEnumber of rows and COLSIZEnumber of columns, 4.3 Assume that values have been assigned to all the elements of playland play2. Also assume that an int variable trickyhas been declared and intialised to 0. Use nested forloops and write down the necessary C++ statements to do the following: Each...
4.3 Assume that values have been assigned to all the elements of playland play2. Also assume that an int variable trickyhas been declared and intialised to 0. Use nested forloops and write down the necessary C++ statements to do the following: Each row of playlis compared element by element to the corresponding row of play2. If the elements are equal, add the value of one element to tricky. If the elements are not equal, add the sum of the two...
QUESTION 4 16 marks 4.1 Declare two integer constants ROWSIZE equal to 4 and COLSIZEequal to 4. (4) 4.2 Declare two inttwo‐dimensional arrays, namely play1with ROWSIZEnumber of rows and COLSIZEnumber of columns, and play2with ROWSIZEnumber of rows and COLSIZEnumber of columns 4.3 Assume that values have been assigned to all the elements of play1and play2. Also assume that an int variable trickyhas been declared and intialised to 0. Use nested forloops and write down the necessary C++ statements to do the following:...
Write a program that reads a matrix from the keyboard and displays the summations of all its rows on the screen. The size of matrix (i.e. the number of rows and columns) as well as its elements are read from the keyboard. A sample execution of this program is illustrated below: Enter the number of rows of the matrix: 3 Enter the number of columns of the matrix: 4 Enter the element at row 1 and chd umn 1: 1...
Question 1 a. Define the following matrices in a script file (M-file), ? = ( 8 9 10 11; 23 9 16 15 ;11 12 3 6; 1 2 8 9 ) ? = ( 2 21 7 15; 12 4 8 22; 23 9 5 13; 23 4 21 22) ℎ = (4 9 12 15) b. Add suitable lines of codes to the M-file to do the following. Each of the following points should be coded in only...
S.A vector IS givell by [5, 17,-3, 8, 0,-7, 12, 15, 20,-6, 6, 4,-7, 16]. Write a program as a 3 or 5, and, raises to the power of 3 the elements that are script tile that doubles the elements that are positive and are divisible by negative but greater than -5. following values. The value of each element in the first row is the number of the 6. Write a program in a script file that creates an matrix...
I'm a little crunched for time and need some help with these first two questions. Thank you! Question 1.) Write a Java program that reads in sequence of integers from the user until user enters a negative number and stores them in an Integer ArrayList. Once read, display a bar chart based on the values stored in the ArrayList. For example, if the user inputs 2, 5, 3, 8, 4, and -1, then your program should display the bar chart...