•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 428,563 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,624 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 601 | Replies: 2
Hello,
The code below calculates the determinant of the matrix. I know that the method of global 2-d pointers is a poor programming practice (so u don't need to reply saying that!!!), but it is a simple method for an amateur programmer. As the code didn't work, I set two watches,
(After giving the input as a 3x3 matrix with elements numbered from 1 to 9) one on e[k][l] & another on b[k1][l1]. To my surprise, b[k1][l1] got modified on its own inspite the fact that e[k][l] at k=1 and l=1 had the value of 5.
Somebody plz help me out.
-Jishnu.
The code below calculates the determinant of the matrix. I know that the method of global 2-d pointers is a poor programming practice (so u don't need to reply saying that!!!), but it is a simple method for an amateur programmer. As the code didn't work, I set two watches,
(After giving the input as a 3x3 matrix with elements numbered from 1 to 9) one on e[k][l] & another on b[k1][l1]. To my surprise, b[k1][l1] got modified on its own inspite the fact that e[k][l] at k=1 and l=1 had the value of 5.
Somebody plz help me out.
-Jishnu.
c Syntax (Toggle Plain Text)
#include<iostream.h> #include<iomanip.h> #include<conio.h> #include<stdio.h> #include<stdlib.h> #include<math.h> void show(float **a,int n); float det(float **b,int n); void minor(float **a,int o,int i,int j); void main() { clrscr(); int o,i,j; float **a,ans; cout<<"Enter The Order Of Matrix:"; cin>>o; for(i=0;i<o;i++) a[i]=new float[o]; for(i=0;i<o;i++) for(j=0;j<o;j++) cin>>a[i][j]; ans=det(a,o); cout<<ans; getch(); } void show(float **a,int n) { cout<<"\n"; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) {cout<<setw(8)<<a[i][j]<<" ";} cout<<"\n\n"; } } float **b; float det(float **c,int n) { float ans=0; float *d; d=new float[n]; for(int i=0;i<n;i++) d[i]=c[0][i]; if(n>2) { for(int i=0;i<n;i++) { minor(c,n,0,i); if(i%2==0) ans+=d[i]*det(b,n-1); else ans-=d[i]*det(b,n-1); } } if(n==2) { return(c[0][0]*c[1][1]-c[0][1]*c[1][0]); } return ans; } void minor(float **e,int o,int i,int j) { int k1=0,l1; for(int k=0;k<o;k++) { l1=0; for(int l=0;l<o;l++) { if(k==i) {k1--;break;} if(l==j) continue; [b][color=red]b[k1][l1]=e[k][l];:-O [/color][/b] l1++; } k1++; } }
Last edited by Ancient Dragon : Jun 4th, 2007 at 8:59 am. Reason: add code tags
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Programming Problem (C++)
- A chal;lenging debugging problem : NEW (C)
- Making a log file global (C++)
- Urgent Pls Help: My codes are in errors! (C++)
- Urgent: I need Help in c++.net! (ASP.NET)
Other Threads in the C Forum
- Previous Thread: Generating sine wave
- Next Thread: What input reading functions are there in C?



Threaded Mode