0% found this document useful (0 votes)
23 views3 pages

Array Declaration

This document contains C code to input and print a 2D matrix of integers. It defines functions to input values into a 2D integer matrix from the user and print out the matrix. The main function declares a 2D integer matrix, gets its dimensions from the user, calls the input function to populate it, and then calls the print function to output the matrix.

Uploaded by

PS Surya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Array Declaration

This document contains C code to input and print a 2D matrix of integers. It defines functions to input values into a 2D integer matrix from the user and print out the matrix. The main function declares a 2D integer matrix, gets its dimensions from the user, calls the input function to populate it, and then calls the print function to output the matrix.

Uploaded by

PS Surya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <stdio.

h>

#include<stdlib.h>>

void inputMatrix(int **matrix, int rows, int cols);

void printMatrix(int **matrix, int rows, int cols);

int main()

int **matrix;

int ROWS, COLS;

int i, j;

printf("Enter matrix dimensions\n");

scanf("%d %d", &ROWS, &COLS);

matrix = (int **)malloc(ROWS*COLS*sizeof(int *));

printf("Enter elements in %dx%d matrix.\n", ROWS, COLS);

inputMatrix(matrix, ROWS, COLS);

printf("Elements of %dx%d matrix.\n", ROWS, COLS);

printMatrix(matrix, ROWS, COLS);

return 0;

}
void inputMatrix(int **matrix, int rows, int cols)

int i, j;

for(i = 0; i < rows; i++)

for(j = 0; j < cols; j++)

scanf("%d", (*(matrix + i) + j));

void printMatrix(int **matrix, int rows, int cols)

int i, j;

for (i = 0; i < rows; i++)

for (j = 0; j < cols; j++)


{

printf("%d ", *(*(matrix + i) + j));

printf("\n");

You might also like