Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Semrush - keyword research tool

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Teach Your Child To Read

Disclosure: My content contains affiliate links.

31,649 questions

41,702 answers

573 users

How to print a specific column of a matrix in C++

1 Answer

0 votes
#include <iostream>

#define COLS 4
 
void print_column(int matrix[][COLS], int rows, int col) {
    for (int i = 0; i < rows; i++) {
        std::cout << matrix[i][col] << " ";
    }
}
 
int main()
{
    int matrix[][COLS] = {
                    {3, 2, 5, 1},
                    {4, 7, 6, 5},
                    {9, 3, 0, 1}
    };
 
    int rows = sizeof(matrix) / sizeof(matrix[0]);
 
    print_column(matrix, rows, 1);
}
 
 
 
 
 
/*
 
run:
 
2 7 3 
 
*/

 



Learn & Practice Python
with the most comprehensive set of 13 hands-on online Python courses
Start now


answered Jul 9 by avibootz

Related questions

...