//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[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[j];
}
if(i+j==n-1)
diag2+=a[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[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];


}
cout<<" column of column "<<n<<" is "<<sum;
}
}

Recommended Answers

All 6 Replies

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).

So what's your question? I see nothing but a bunch of code in need of a few band aids, but no question.

wat does it mean by primary expression required before int

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

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

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

You're right, you can put function prototypes in a block. But then they're only visible to the end of the block.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.