Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program in C++ that displays the main diagonal of its 2D array with commas but avoiding to put a comma in the last

Write a program in C++ that displays the main diagonal of its 2D array with commas but avoiding to put a comma in the last number.

Example:

1 2 3

4 5 6

8 9 7

output: 1, 5, 7 (Notice that the last number does not have any comma)

This is the code I have so far:

#include

int main(void) { int myArray[][4] = { {1,2,3,4}, {5,6,7,8}, {7,9,3,8} }; int width = 4, height = 3;

for (int i = 0; i < height; ++i) { for (int j = 0; j < width; ++j) { std::cout << myArray[i][j] << ' '; } std::cout << std::endl; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

Describe the role of free trade zones (FTZs) in global logistics.

Answered: 1 week ago

Question

Were all members comfortable brainstorming in front of each other?

Answered: 1 week ago

Question

Explain the importance of Human Resource Management

Answered: 1 week ago

Question

Discuss the scope of Human Resource Management

Answered: 1 week ago

Question

Discuss the different types of leadership

Answered: 1 week ago

Question

Write a note on Organisation manuals

Answered: 1 week ago

Question

Define Scientific Management

Answered: 1 week ago