0% found this document useful (0 votes)
7 views1 page

3x3 Matrix Using 2D Array C Program

The document provides a C program that inputs and displays a 3x3 matrix using a two-dimensional array. It includes code that prompts the user for matrix elements and then prints the matrix in a formatted manner. The explanation outlines the structure and functionality of the program, emphasizing the use of nested loops and standard input/output functions.
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)
7 views1 page

3x3 Matrix Using 2D Array C Program

The document provides a C program that inputs and displays a 3x3 matrix using a two-dimensional array. It includes code that prompts the user for matrix elements and then prints the matrix in a formatted manner. The explanation outlines the structure and functionality of the program, emphasizing the use of nested loops and standard input/output functions.
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

Question: Write a C program to input and display a 3×3 matrix using a two-dimensional array.

C Program:
#include <stdio.h>

int main() {
int matrix[3][3];
int i, j;

// Input elements of the 3x3 matrix


printf("Enter elements of 3x3 matrix:\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
scanf("%d", &matrix[i][j]);
}
}

// Display the 3x3 matrix


printf("3x3 Matrix is:\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}

return 0;
}

Explanation:
1. A two-dimensional array matrix[3][3] is declared to store the elements of a 3×3 matrix.
2. Two nested for loops are used to take input for each row and column of the matrix.
3. The scanf() function is used to read the matrix elements from the user.
4. Another set of nested loops is used to display the matrix in proper row and column format.
5. The printf() function is used to print the matrix elements on the screen.
6. This program demonstrates the use of a two-dimensional array in C programming.

You might also like