#include<iostream.h>
#include<conio.h>

void main()
{	clrscr();
	int A[20][2],n,sum;
	cout<<"\n\tEnter the no. of terms: ";
	cin>>n;
	cout<<"\n\tEnter "<<2*n<<" numbers to the "<<n<<"*2 array: ";

	for(int i=0;i<2;i++)
	{	for(int j=0;j<n;j++)
		cin>>A[i][j];
	}

	cout<<"\n\n\tThe Array you entered is: ";
	for(i=0;i<2;i++)
	{	cout<<"\n";
		{	for(int j=0;j<n;j++)
			cout<<A[i][j]<<" ";
		}
	}

	for(i=0;i<2;i++)
	{	sum=0;
		for(int j=0;j<n;j++)
		sum+=A[i][j];

		cout<<"\n\tSum of row "<<i+1<<" is "<<sum;
	}
	cout<<"\n";
	for(i=0;i<n;i++)
	{	sum=0;
		for(int j=0;j<2;j++)
		sum+=A[j][i];

		cout<<"\n\tSum of column "<<i+1<<" is "<<sum;
	}

	getch();
}
Re: A[0][3]&....... gets replaced by A[0][0]........ 80 80

Is that not supposed to happen? If not, why did you code it that way?

Read this http://www.daniweb.com/software-development/cpp/threads/78223 and ask again.

Re: A[0][3]&....... gets replaced by A[0][0]........ 80 80

Well Captain Neo! Since i didn't find any error with your code, i took the liberty to compile it.
And here is what i got:

Enter the no. of terms: 5

        Enter 10 numbers to the 5*2 array: 1
2
3
4
5
6
7
8
9
10


        The Array you entered is:
1 2 6 7 8
6 7 8 9 10
        Sum of row 1 is 24
        Sum of row 2 is 40

        Sum of column 1 is 7
        Sum of column 2 is 9
        Sum of column 3 is 14
        Sum of column 4 is 16
        Sum of column 5 is 18

So for what, did you code this? And Next time onward be descriptive in showing what problem you have. Don't just throw your code in and wait for others to find the error...

Re: A[0][3]&....... gets replaced by A[0][0]........ 80 80

Ok! Spotted the error.


You declared it like this

int A[20][2],n,sum;

But
User loop is

for(int i=0;i<2;i++)
	{	for(int j=0;j<n;j++)
		cin>>A[i][j];
	}

Here your counter says j<n, but how can j go more than two.

You should have put it like this

int A[2][20],n,sum;

Hope this helped

Be a part of the DaniWeb community

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