Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
can anyone help me in writing a code for cramer's rule of mathematics in VB.NET?
please anyone knows then provide me the code of this program.
i know the code in c language but there is some problem in converting it in VB.NET/C#.NET

the code is.


CRAMER’S rule................:)
C++
#include <stdio.h>

int det3(int a[3][3]);

int main(void)
{
	int A[3][3];
	int B[3];

	printf("This program uses Cramer's Rule to solve a linear system.\
			Enter each of 3 linear equations as four integers separated by space.\
			  For example, x - 2y + 3z = 4 should be entered as 1 -2 3 4");
	printf("\n\nEnter equation 1: ");
	scanf("%i %i %i %i", &A[0][0], &A[0][1], &A[0][2], &B[0]);
	printf("Enter equation 2: ");
	scanf("%i %i %i %i", &A[1][0], &A[1][1], &A[1][2], &B[1]);
	printf("Enter equation 3: ");
	scanf("%i %i %i %i", &A[2][0], &A[2][1], &A[2][2], &B[2]);

	/*Finding determinants*/

	int detx[3][3] = {{B[0],A[0][1],A[0][2]},{B[1],A[1][1],A[1][2]},
						  {B[2],A[2][1],A[2][2]}};
	int dety[3][3] = {{A[0][0],B[0],A[0][2]},{A[1][0],B[1],A[1][2]},
						  {A[2][0],B[2],A[2][2]}};
	int detz[3][3] = {{A[0][0],A[0][1],B[0]},{A[1][0],A[1][1],B[1]},
						  {A[2][0],A[2][1],B[2]}};

	/* Code that determines if the system has a unique solution */

	  if(det3(A)!=0)
			 printf("\nSystem has a unique solution ( %d, %d, %d)",
			 det3(detx)/det3(A), det3(dety)/det3(A), det3(detz)/det3(A));
	  else
			 printf("\nSystem does not have a unique solution because determinant is 0");

	return 0;
}
int det3(int a[3][3])
{
	return (a[0][0]*a[1][1]*a[2][2])-(a[0][0]*a[1][2]*a[2][1]),
				+(a[0][1]*a[1][2]*a[2][0])-(a[0][1]*a[1][0]*a[2][2]),
				+(a[0][2]*a[1][0]*a[2][1])-(a[0][2]*a[1][1]*a[2][0]);
}
Posted
Updated 10-Oct-11 3:33am
v3
Comments
André Kraak 10-Oct-11 8:26am    
This looks like homework.

It would be best if you do your own homework. It is given to you so that you will learn something, think about what have been told. Read your text books and give it a try.

If you have a specific problem with your implementation later on post a detailed and specific question and we will gladly try to help you solve it. Include relevant code from your implementation.
shweta89 10-Oct-11 9:07am    
@andre thats not a homework actually i don't know .NET well ...i m just trying to learn it i know c and c++ well..
shweta89 10-Oct-11 8:37am    
yeah i have a problem in assigning array element to another array detx(2)(3) ..as u can in code written above...

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900