Subscribe to Feeds

Send Your COMPLETED Projects To georgepj@hotmail.com

We'll Publish It With Your Name :-)

Programs Can Also Be Downloaded From The Folders Below....[Or Scroll Down]

Array Diagonal,Row,Column - Sum

Click Here To Download C++ File Of This Program

 //SUM OF BOTH DIAGONALS  
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
#include<process.h>
int sum1(int a[50][50],int r)
{
int s=0;
for(int i=0;i<r;i++)
{ s=s+a[i][i];}
return(s);
}
int sum2(int a[50][50],int r)
{
int s=0;
int j;
j=r-1;
for(int i=0;i<r;i++)
s=s+a[i][j--];
return(s);
}
void row(int a[50][50],int r)
{
int s=0;
for(int i=0;i<r;i++)
{
s=0;
for(int j=0;j<r;j++)
{
s=s+a[i][j];
}
cout<<"Sum of Row "<<i+1<<" = "<<s<<endl;
}}
void col(int a[50][50],int r)
{ int s=0;
for(int i=0;i<r;i++)
{
s=0;
for(int j=0;j<r;j++)
{
s=s+a[j][i];
}
cout<<"Sum of Column "<<i+1<<" = "<<s<<endl;
}}
void main()
{
clrscr();
int i,s,j,r,c,ch,a[50][50];
x:
cout<<"Entr Array Limit--(Enter only Row as R=C)"<<endl;
cin>>r;
cout<<"Enter Array"<<endl;
for(i=0;i<r;i++)
{
for(j=0;j<r;j++)
{
cin>>a[i][j];
}
}
y:
cout<<endl<<endl<<" Enter Choice :"<<endl<<"Sum of---- 1:main 2:Secondary 3.Rows 4.Columns 5.Re-enter 6.Exit "<<endl;
cin>>ch;
switch(ch)
{
case 1:
s=sum1(a,r);
cout<<"Sum = "<<s<<endl;
goto y;
case 2 :
s=sum2(a,r);
cout<<"Sum = "<<s<<endl;
goto y;
case 3:
row(a,r);
goto y;
case 4:
col(a,r);
goto y;
case 5:
goto x;
case 6:
exit(0);
default :
cout<<"Wrong Choice"<<endl;
break;
}
getch();
}

No comments: