help me

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aruna
    New Member
    • Aug 2006
    • 6

    #1

    help me

    iam not getting the proper output.so please help me


    Code:
    /*to find determinant of matrix */
    # include <stdio.h>
    # include <conio.h>
    # include <math.h>
    double det(double fArray[3][3],int nNum);
    void main()
    {
    	int nNum,nCtr1,nCtr2;
    	double fResult,fArray[3][3];
    	clrscr();
    	printf ("enter the size of matrix");
    	scanf("%d",&nNum);
    	printf("enter the elts ");
    	for(nCtr1=0;nCtr1<nNum;nCtr1++)
    	{
    		for(nCtr2=0;nCtr2<nNum;nCtr2++)
    			scanf("%e",&fArray[nCtr1][nCtr2]);
    
    
    	}
    	fResult=det(fArray,nNum);
    	printf("the determinant of matrix is %e",fResult);
    
    	getch();
    }
    
    
    
    
    
    	double det(double fArray[3][3],int nNum)
    	{
    	int nCtr1,nCtr2,nCtr3,nCtr4,nCtr5,nCtr6;
    	double fResult=0;
    	double fTemp[3][3];
    	if(nNum==2)
    	{
    	return fResult=fArray[0][0]*fArray[1][1]-fArray[0][1]*fArray[1][0];
    	}
    	else
    	{
                      nCtr1=0;
    	for(nCtr2=0;nCtr2<nNum;nCtr2++)
                    nCtr3=0;			
                    for(nCtr5=0;nCtr5<nNum;nCtr5++)
    	{
    	nCtr4=0;
    	if(nCtr5!=nCtr1)
                    {
    	for(nCtr6=0;nCtr6<nNum;nCtr6++)
    	{
    	if(nCtr6!=nCtr2)
    	{
    								fTemp[nCtr3][nCtr4]=fArray[nCtr5][nCtr6];
    								nCtr4++;
    	}
                     }
    	nCtr3++;
    
    	}
    	}
                    }
    	if((nCtr1+nCtr2)%2==0)
    	fResult=fResult+fArray[nCtr1][nCtr2]*det(fTemp,nNum-1);
    	else
    	fResult=fResult-fArray[nCtr1][nCtr2]*det(fTemp,nNum-1);
    
    
    	 }
    	return fResult;
    
    	}
    Last edited by Banfa; Sep 7 '06, 09:16 PM. Reason: Added code tags
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    This code doesn't compile, you have the braces wrong.

    Taking a guess at where to put the missing brace then I find that you are using doubles in scanf. scanf expects pointers to floats so your data is not being entered correctly and as the say garbage in, garbage out.

    Comment

    Working...