# WAP in C to input 3*3 Matrix and convert in to 4*4 matrix!

The program in C to Input a 3 * 3 matrix using keyboard, and to convert it in to 4*4 matrix by adding corresponding row and columns is given below:

``````#include <stdio.h>

#define ROWS 3
#define COLS 3
#define NEW_ROWS 4
#define NEW_COLS 4

int main() {
int arr[ROWS][COLS], new_arr[NEW_ROWS][NEW_COLS], i, j;

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

// Copy the elements of the 3x3 matrix to the 4x4 matrix
for (i = 0; i < ROWS; i++) {
for (j = 0; j < COLS; j++) {
new_arr[i][j] = arr[i][j];
}
}

// Add the corresponding rows and columns
for (i = 0; i < ROWS; i++) {
new_arr[i][COLS] = 0;
new_arr[ROWS][i] = 0;
for (j = 0; j < COLS; j++) {
new_arr[i][COLS] += arr[i][j];
new_arr[ROWS][i] += arr[i][j];
new_arr[ROWS][COLS] += arr[i][j];
}
}

printf("The 4x4 matrix is:\n");
for (i = 0; i < NEW_ROWS; i++) {
for (j = 0; j < NEW_COLS; j++) {
printf("%d ", new_arr[i][j]);
}
printf("\n");
}

return 0;
}
``````

## Output:

Enter the elements of the 3×3 matrix:
45
67
33
12
89
99
54
33
21
The 4×4 matrix is:
45 67 33 145
12 89 99 200
54 33 21 108
145 200 108 22299

## Pro-Tips💡

This program defines two integer constants ROWS and COLS to set the size of the 3×3 array and another two constants NEW_ROWS, NEW_COLS to set the size of the 4×4 array.

Then, it reads in the elements of the 3×3 array using nested for loops.

Next, it uses another set of nested for loops to copy the elements of the 3×3 array to the 4×4 array.

Then it uses another set of nested for loops to add the corresponding rows and columns of the 3×3 array and update the 4×4 array.

Finally, it prints out the 4×4 array.

### Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

### Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

### Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly. Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

## C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

## C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

## C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

## C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

## C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

## C# Program to Delete Element at Desired position From Array

The Program in C# Program to Delete Element at Desired position From Array is given below: Output: Hello Codeauri Family, enter the number of elements in the array:4Enter…

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X