Could you please write this code in C language?? //class declaration public class matrix { //main method public static void main(String[] args) { //create Scanner and get user input Scanner sc = new Scanner(System.in); System.out.print("Enter an integer : "); int n = sc.nextInt(); //create 3 matrix int matrix1[][] = new int[6][6]; int matrix2[][] = new int[6][6]; int matrix3[][] = new int[6][6]; //generate values for first matrix for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { if(i+j == 0 || i+j == 10) matrix1[i][j] = n; else if(i+j == 1 || i+j == 9 ) matrix1[i][j] = n-1; else if(i+j == 2 || i+j == 8 ) matrix1[i][j] = n-2; else if(i+j == 3 || i+j == 7 ) matrix1[i][j] = n-3; else if(i+j == 4 || i+j == 6 ) matrix1[i][j] = n-4; else matrix1[i][j] = 2*n; } } //generate values for second matrix for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { if(i<3 && j<3) matrix2[i][j] = n; else if(i<3 && j>=3) matrix2[i][j] = n+1; else if(i>=3 && j<3) matrix2[i][j] = n+2; else matrix2[i][j] = n+3; } } //generate values for third matrix for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { if(i+j == 0 || i+j == 10) matrix3[i][j] = n - (5*2); else if(i+j == 1 || i+j == 9 ) matrix3[i][j] = n - (4*2); else if(i+j == 2 || i+j == 8 ) matrix3[i][j] = n - (3*2); else if(i+j == 3 || i+j == 7 ) matrix3[i][j] = n - (2*2); else if(i+j == 4 || i+j == 6 ) matrix3[i][j] = n - (1*2); else matrix3[i][j] = n; } } //print the matrix print(matrix1); print(matrix2); print(matrix3); } //method to print matrix public static void print(int[][] arr) { System.out.println(); for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr.length; j++) { System.out.printf("%4d",arr[i][j]); } System.out.println(); } } }
//class declaration
public class matrix {
//main method
public static void main(String[] args) {
//create Scanner and get user input
Scanner sc = new Scanner(System.in);
System.out.print("Enter an integer : ");
int n = sc.nextInt();
//create 3 matrix
int matrix1[][] = new int[6][6];
int matrix2[][] = new int[6][6];
int matrix3[][] = new int[6][6];
//generate values for first matrix
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
if(i+j == 0 || i+j == 10)
matrix1[i][j] = n;
else if(i+j == 1 || i+j == 9 )
matrix1[i][j] = n-1;
else if(i+j == 2 || i+j == 8 )
matrix1[i][j] = n-2;
else if(i+j == 3 || i+j == 7 )
matrix1[i][j] = n-3;
else if(i+j == 4 || i+j == 6 )
matrix1[i][j] = n-4;
else
matrix1[i][j] = 2*n;
}
}
//generate values for second matrix
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
if(i<3 && j<3)
matrix2[i][j] = n;
else if(i<3 && j>=3)
matrix2[i][j] = n+1;
else if(i>=3 && j<3)
matrix2[i][j] = n+2;
else
matrix2[i][j] = n+3;
}
}
//generate values for third matrix
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
if(i+j == 0 || i+j == 10)
matrix3[i][j] = n - (5*2);
else if(i+j == 1 || i+j == 9 )
matrix3[i][j] = n - (4*2);
else if(i+j == 2 || i+j == 8 )
matrix3[i][j] = n - (3*2);
else if(i+j == 3 || i+j == 7 )
matrix3[i][j] = n - (2*2);
else if(i+j == 4 || i+j == 6 )
matrix3[i][j] = n - (1*2);
else
matrix3[i][j] = n;
}
}
//print the matrix
print(matrix1);
print(matrix2);
print(matrix3);
}
//method to print matrix
public static void print(int[][] arr) {
System.out.println();
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length; j++) {
System.out.printf("%4d",arr[i][j]);
}
System.out.println();
}
}
}
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)