Input a matrix in 3-D array and check if it is identity matrix or not – Simple loop and array question , matrix question , 2d array question
Input a matrix in 3-D array and check if it is identity matrix or not – Simple loop and array question , matrix question , 2d array question
IN JAVA LANGUAGE :
package com.company; import java.util.Scanner; public class identityMatrix { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int[][] arr = new int[3][3]; int i,j; System.out.println("Input values in matrix : "); for(i = 0 , i<3 , i++) { for (j = 0 ; j<3 ; j++) { arr[i][j] = sc.nextInt(); } } boolean flag = false; for(i = 0 , i<3 , i++) { for (j = 0 ; j<3 ; j++) { if( i == j ) { arr[i][j] == 1; break; } if( i != j ) { arr[i][j] == 0; break; } } } if (i==3 && j == 3) { System.out.println("Identity Matrix"); } else { System.out.println("Not identity matrix"); } } }
IN C LANGUAGE :
#include<stdio.h>
int main(int argc, char const *argv[])
{
int arr[10][10],r,c,i,j,flag=0;
printf(“enter the no of rows and columns=\n”);
scanf(“%d%d”,&r,&c);
printf(“enter the elements:\n”);
{
for(i=0; i<r; i++)
{
for(j=0; j<c; j++)
scanf(“%d” ,&arr[i][j]);
}
}
for(i=0; i<r; i++)
{
for(j=0; j<c; j++)
{
if(i==j && arr[i][j]!=1)
{
flag=-1;
break;
}
else if (i!=j && arr[i][j]!=0)
{
flag = -1;
break;
}
}
}
if(flag==0)
{
printf(“it is an identity matrix\n”);
}
else
{
printf(“not an identity matrix\n”);
}
return 0;
}
Programmed by : Sadhana
Topics Covered :
- declare matrix in c
- java matrix program
- arrays in c
- 2d array in java
- creation of matrix in java
- matrix c
- arrays in cpp
- 2d array in c
- traverse matrix in java
- matrix cpp
- 2d array in cpp
- arrays in c language
- arrays
- matrix in c
- passing arrays as arguments in c
- create a matrix in javascript
- matrix in cpp
- 2d array
- traverse matrix using for loop
- 2d array in java using scanner
- programming tutorial
- programming tutorial c++
- core java tutorial
- nested loops
Thanks for reading this blog. Hope you get satisfied with the blog and definitely this blog must have valued your time and effort of reading.
Take a time to connect our other digital creations such as Instagram , Facebook and Youtube.
Β Social MediaΒ LinksΒ ofΒ Tech DCodeΒ :
Β YouTube :Β https://www.youtube.com/channel/UCjJnEdeugftBwQ3yMuD4B_A
Β Instagram :Β https://www.instagram.com/thetechdcode/
Β Facebook Page :Β https://www.facebook.com/thetechdcode
Β Twitter :Β https://twitter.com/thetechdcode
Β Telegram Channel :Β https://t.me/thetechdcode
Β Tech DCode Linktree :Β https://linktr.ee/thetechdcode
Β My Personal Handles :Β https://linktr.ee/virtualshivamin
Β Social Media LinksΒ ofΒ SHIVAM SINGHΒ (OWNER) :
Β Instagram :Β https://www.instagram.com/virtualshivamin/
Β Facebook Page :Β https://www.facebook.com/virtualshivamin/
Β Twitter :Β https://twitter.com/virtualshivamin/
Β Personal Linktree :Β https://linktr.ee/virtualshivaminΒ
[…] solution here […]