![]() |
| ||
| a real challenge this time //square matrix #include<iostream.h> #include<conio.h> #include<stdio.h> int main() { void diagsum(int a[10][10],int n); void rowsum (int a[10][10],int n); void colsum (int a[10][10],int n); int a[10][10]; int n,opt; cout<<" enter the size of matrix (say 4 for 4/4etc..) "; cin>>n; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) {cin>>a[i][j]; } } for(int k =0;k<n;k++) { for(int l=0;l<n;l++) {cout<<a[k][l]<<"\t"; } cout<<endl; } cout<< " enter 1 for diag sum , 2 for row sum , 3 for column sum "; cin>>opt; switch(opt) { case 1: diagsum(int a,int n);/* the compiler is showing error from here .it says - primary expression required before int */ getch(); break; case 2: rowsum(int a, int n); getch(); break; case 3: colsum(int a, int n); getch(); break; default: cout<<" wrong option "; } } void diagsum(int a[10][10],int n) { int diag1=0,diag2=0; for(int i=0;i<n;i++) { for (j=0;j<n;j++) { if(i==j) { diag1+=a[i][j]; } if(i+j==n-1) diag2+=a[i][j]; } cout<<" diagonal 1 = "<<diag1; cout<<"\n diagonal 2 = "<<diag2; } void rowsum (int a[10][10],int n) { int row,sum; for(int i=0;i<n;i++) { for int j=0;j<n;j++) { sum+=a[i][j]; } cout<<" sum of row "<<n<<" is "<<sum; } } void colsum (int a[10][10],int n) { int col,sum; for(int i=0;i<n;i++) { for int j=0;j<n;j++) { sum+=a[j][i]; } cout<<" column of column "<<n<<" is "<<sum; } } |
| ||
| Re: a real challenge this time Dont declare functions inside of other functions (in this case inside main(), and when you call a function and need to pass it arguments, don't indicate the argument type, just the argument name or an objects address (if the function is expecting a pointer and what you have is an object). |
| ||
| Re: a real challenge this time So what's your question? I see nothing but a bunch of code in need of a few band aids, but no question. |
| ||
| Re: a real challenge this time wat does it mean by primary expression required before int |
| ||
| Re: a real challenge this time why not to declare functions inside main??? it is not a prob as far as i know , i have made a quite a few prog doing the same |
| ||
| Re: a real challenge this time In switch case u r declaring a prototype...it should be a function call there...from next time use code tags ....and instead of arguing with people in the forum u should accept ur mistakes....try learning things....in your previous posts u said u downloaded DEV....i don't think u r using that Note: Everyone is not gonna post corrected codes for u here always |
| ||
| Re: a real challenge this time Quote:
|
| All times are GMT -4. The time now is 4:47 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC