Question

The language is C++ Use the following definition in questions 4 and 5: int x [4][4]...

The language is C++

Use the following definition in questions 4 and 5:

int x [4][4] = {{1,2,3,4}, {5,6,7,8}, {9,8,7,3}, {2,1,7,1}};

4. Give the value in sum after the following statements are executed:

int sum = x[0][0];

for (int k = 1; k <=3; ++k) sum += x[k][k];

5. Give the value in sum after the following statements are executed:

int sum = 0;

for (int index1 = 0; index1 < 4; index1++)

for (int index2 = 0; index2 < 4; index2++)

if (x[index1][index2]> x[index1-1]index2])

sum ++;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:-

4. Give the value in sum after the following statements are executed:

int sum = x[0][0];

for (int k = 1; k <=3; ++k) sum += x[k][k];

output:- 15

5. Give the value in sum after the following statements are executed:

int sum = 0;

for (int index1 = 0; index1 < 4; index1++)

for (int index2 = 0; index2 < 4; index2++)

if (x[index1][index2]> x[index1-1]index2])

sum ++;

output:- 6

Add a comment
Know the answer?
Add Answer to:
The language is C++ Use the following definition in questions 4 and 5: int x [4][4]...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • QUESTION 1 Given two double variables named x and y, which of the following statements could...

    QUESTION 1 Given two double variables named x and y, which of the following statements could you use to initialize both variables to a value of 0.0? a. x | y = 0.0; b. x = y = 0.0; c. x, y = 0.0; d. none of the above 1 points    QUESTION 2 When you use a range-based for loop with a vector, you a. can avoid out of bounds access b. must still use a counter variable c....

  • 4. Given the following code, int x = 5, n; do{ n = 0; for (int...

    4. Given the following code, int x = 5, n; do{ n = 0; for (int i = 0; i < x; i++) { n = n + x; System.out.println(n); } while (x > 1); a) What will be the value of x after the code segment is executed? Initial value of x 5 b) What is the output of the code segment? c) Explain how the flow of control moves in the given code segment. When explaining, show how...

  • 5. What is the output of the following section of a program int a[10] = {2,5,1,6,x,7,0,3,y,8};       ...

    5. What is the output of the following section of a program int a[10] = {2,5,1,6,x,7,0,3,y,8};        for(int i=0;i<9;i++)      a[i]=a[i+1]; for(int i=0;i<8;i++)      cout<<a[i]<<” “; cout<<endl; 6. What will be shown on the output screen after following statements are executed? char a[ ]="I have a part time job"; int c=x, i=0 while(a[i]!=’\0’){      if(a[i]==' '){           c++;           cout<<endl;      }      else           cout<<a[i];      i++; } cout<<c<<endl; 7. After following statements are executed, what are the outputs char a[ ]= "Fresno City College";        for (i...

  • After the following declarations and statements are executed:       int i, j, k ;       boolean...

    After the following declarations and statements are executed:       int i, j, k ;       boolean c;       float x, y,   z;       int[ ] num = {4, 1, 2, 3, 8};       i = 3;       j = 5;       x = 4.3;       y = 58.209;       c = !(i > j) ; what is the value of c

  • CHAPTER 6 QUESTION 1 Which of these names follows the naming conventions for constants presented in...

    CHAPTER 6 QUESTION 1 Which of these names follows the naming conventions for constants presented in this chapter? a. WeeksInYear b. Weeks_In_Year c. weeks_in_year d. WEEKS_IN_YEAR 1 points QUESTION 2 Which of the following data types can you not use to store the value 500? a. float b. char c. int d. double 1 points QUESTION 3 What values are in the vector named pressures after the following code is executed? vector pressures; pressures.push_back(32.4); pressures.push_back(33.5); pressures.insert(pressures.begin(), 34.2); int index =...

  • Need help with these questions in C programming: 9. What is the output of the following...

    Need help with these questions in C programming: 9. What is the output of the following code? int X[10]={0}; int N=4; for(int k=0; k<N:k++) X[k] = k*2: printf("%d", X[N/2]; 10. Write a single statement to accomplish each of the following. Assume that each of these statements applies to the same program. a. Write a statement that opens file "oldmast.dat" for reading and assigns the returned file pointer to ofPtr. b. Write a statement that opens file "trans.dat" for writing and...

  • c language not c++ c language int mininum(int a[135) int i; int min. Question 2 (4...

    c language not c++ c language int mininum(int a[135) int i; int min. Question 2 (4 points) If ptr is an integer pointer and x in an integer variable then write one statement to set ptr to point to x then write another statement to increment x by 10 using ptr (not using x) (4 points) Question 3 (4 points) Saved

  • should be in C language What is the output of the following segment of C code:...

    should be in C language What is the output of the following segment of C code: void CapsLetter (char* x, charl); int main() { char* text; text="This is some sample text."; CapsLetter(text, 'e'); printf("%s", text); return 0; سی void Caps Letter (char* x, char 1) { int i=0; while (x[i]!='\0') { if (x[i]==1) x[i]=1-32; } 1. This is som sample text. 2. THIS IS SOME SAMPLE TEXT. 3. This is some sample text. 4. this is some sample text. What...

  • QUESTION 1 What will be displayed as a result of executing the following code? int   x...

    QUESTION 1 What will be displayed as a result of executing the following code? int   x = 5, y = 20; x += 32; y /= 4; cout <<"x = " << x <<"y = " << y; A. x = 32, y = 4 B. x = 9, y = 52 C. x = 37, y = 5 D. x = 160, y = 80 8 points    QUESTION 2 What will be the displayed when the following code...

  • I don’t understand can you help 5. Given the definition and code fragment: (2 points int...

    I don’t understand can you help 5. Given the definition and code fragment: (2 points int matrix[2]13]; int k = 0; for(int i =0; i < 2; i++) for (int j=0, j < 3 ) matrix[i]lj]-k++; The value of matrix[1][1] is

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT