| | |
a real challenge this time
![]() |
•
•
Join Date: Nov 2005
Posts: 31
Reputation:
Solved Threads: 0
//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;
}
}
#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;
}
}
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
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
dwk
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
![]() |
Similar Threads
- What Linux you recomend for Desktop? (Getting Started and Choosing a Distro)
- recommendations for JavaScript learning resources? (JavaScript / DHTML / AJAX)
- Tutorials for Linux (*nix Software)
Other Threads in the C++ Forum
- Previous Thread: Need major help
- Next Thread: Need some help please
| Thread Tools | Search this Thread |
api array based binary bitmap business c++ c/c++ char class classes code coding commentinghelp compile console conversion count decide delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez graph guess gui homeworkhelp homeworkhelper iamthwee ifpug ifstream incrementoperators infinite input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem proficiency program programming project python random read recursion reference rpg string strings temperature template templates test text text-file tree url variable vector video win32 windows winsock word wordfrequency wxwidgets






