C language interview questions solution for freshers beginners placement tricky good pointers answers explanation operators data types arrays structures functions recursion preprocessors looping file handling strings switch case if else printf advance linux objective mcq faq online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c++ tutorials and pdf
int matrix[][]; Scanner s=new Scanner(System.in); Random r = new Random(); public Matrix() { System.out.println("Enter size"); int n=s.nextInt(); int[][] matrix=new int[n][n]; System.out.println("enter the matrix");
14 comments:
thanks....all the programs are very helpful....
Can i get a c program for rank of a matrix???
thank u...........
its helpful..
its very very help full thanks bro
hi... very easy initiative taken....
but i have a doubt... wat is the usinf using a %3 in the first program of finding the determinant of 3x3 matrix??
determinant = determinant + (a[0][i]*(a[1][(i+1)%3]*a[2][(i+2)%3] - a[1][(i+2)%3]*a[2][(i+1)%3]));
Thank you very much
java program to find determinant of n*n matrix using recursion............
--and please call a instance of this class in main method...
import java.util.Random;
import java.util.Scanner;
public class Matrix {
int matrix[][];
Scanner s=new Scanner(System.in);
Random r = new Random();
public Matrix()
{
System.out.println("Enter size");
int n=s.nextInt();
int[][] matrix=new int[n][n];
System.out.println("enter the matrix");
for(int i=0;i<matrix.length;i++)
{
for(int j=0;j<matrix.length;j++)
{
matrix[i][j]=2+(r.nextInt(1000)%5);
}
}
for(int i=0;i<matrix.length;i++)
{
for(int j=0;j<matrix.length;j++)
{
System.out.print(matrix[i][j]+" ");
}
System.out.println();
}
// for(int i=0;i<matrix.length;i++)
// {
// for(int j=0;j<matrix.length;j++)
// {
// matrix[i][j]=s.nextInt();
// }
// }
//
long det=this.findDet(matrix);
System.out.println("determinant is "+det);
}
public long findDet(int matrix[][])
{
if(matrix.length==1)
return matrix[0][0];
if(matrix.length==2)
return (matrix[0][0]*matrix[1][1]-matrix[0][1]*matrix[1][0]);
long sum=0;
for(int j=0;j<matrix.length;j++)
{
int temp[][]=new int[matrix.length-1][matrix.length-1];
this.findNext(matrix, temp, j);
if(j%2==0)
sum=sum+matrix[0][j]*findDet(temp);
else
sum=sum-matrix[0][j]*findDet(temp);
}
return sum;
}
public void findNext(int higher[][],int lower[][],int colNo)
{
for(int i=1,k=0;i<higher.length;i++,k++)
{
for(int j=0,l=0;j<higher.length;l++,j++)
{
if(j!=colNo)
{
lower[k][l]=higher[i][j];
}
else{
l--;
}
}
}
}
}
can u make 6 by 6 matrix using turbo c++ sir ! so needed
determinant of N*N matrix:
public int determinant(int a[][], int n){
int det = 0, sign = 1, p = 0, q = 0;
if(n==1){
det = a[0][0];
}
else{
int b[][] = new int[n-1][n-1];
for(int x = 0 ; x < n ; x++){
p=0;q=0;
for(int i = 1;i < n; i++){
for(int j = 0; j < n;j++){
if(j != x){
b[p][q++] = a[i][j];
if(q % (n-1) == 0){
p++;
q=0;
}
}
}
}
det = det + a[0][x] *
determinant(b, n-1) *
sign;
sign = -sign;
}
}
return det;
}
this program is not working
the program for 3 by 3 matrix doesn't work because it is supposed to be -a[1][0] in the second time for loop execution.
the program for 3 by 3 matrix doesn't work because it is supposed to be -a[1][0] in the second time for loop execution.
the program for 3 by 3 matrix doesn't work because it is supposed to be -a[1][0] in the second time for loop execution.
Post a Comment