|

Home » Ask & Discuss » Board Exams - CBSE, ICSE, State Boards
« Back to Discussion

Computer Science

Cool goIITian

 Joined: 3 Oct 2008 Post: 52
5 Dec 2008 17:05:14 IST
0 People liked this
6
770
2-Dimensional Array
Engineering Entrance , JEE Main , JEE Advanced

Can anyone please give the code of the following program in JAVA.

1                      2                           3

2                     3                           4

2                    3                            5

The above array is a 2-D array.Now i want to print the sum of the numbers of each row just after the row

and the sum of each column just after each  column like this:

1                     2                3            6

2                      3                4            9

2                      3                5            10

5                     8                 12

I hope you understood.

I need the code of this program as early as possible.

2  Rates assured.

Cool goIITian

Joined: 3 Oct 2008
Posts: 52
6 Dec 2008 12:42:46 IST
0 people liked this

its  okkkkkkkkkkkkkkkkkkkkkkkkkkkk

even if anyone gives the answer in C++ or C but  please explain each step with comments

Cool goIITian

Joined: 25 Apr 2008
Posts: 55
19 Dec 2008 10:36:37 IST
1 people liked this

for(i=0;i<4;i++)

{

for(j=0;j<4;j++)

{

i

if(i==2&&j<2)

a[i][j]=i+j;

else

if(i!=3&&j!=3)

a[i][j]=i+j+1;

else

if(i*j!=9){

for(k=0;k<3;k++)

{

if((i==3)

a[i][j]+=a[k][j];

else

if(j==3)

a[i][j]+=a[i][k];

}}}

print the array..

notice the relation betw the subscripts and no stored in them evrything will be clear ....hope this helps...

Cool goIITian

Joined: 31 May 2008
Posts: 51
27 Dec 2008 02:42:25 IST
0 people liked this

create a 2d array 4x4

for(int i=0;i<3;i++)

{

for (int j=0;j<3;j++)

{

s=s+a[i][j];
p=p+a[j][i];
}

a[i][4]=s;
a[4][i]=p;

}

now print the array'

rate if u find useful!!!!!!!!!!!!!

Cool goIITian

Joined: 25 Apr 2008
Posts: 55
29 Dec 2008 15:53:45 IST
1 people liked this

viraat how come a 4*4 hav index 4....also no element should be stored in [3][3] in ur case value of p is stored wat bout the rest of the elements?? now to the problem poser.....do u want me writ a pgm that stores the sum of each row or column...only???please clarify

Cool goIITian

Joined: 25 Apr 2008
Posts: 55
29 Dec 2008 23:08:40 IST
0 people liked this

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

{

s+=a[i][j]

p+=a[j][i];

}

a[i][3]=s;

a[3][i]=p

s=0;

p=0;

}}

this is how it should be....

Cool goIITian

Joined: 5 Dec 2006
Posts: 68
30 Dec 2008 09:22:57 IST
0 people liked this

 Some HTML allowed. Keep your comments above the belt or risk having them deleted. Signup for a avatar to have your pictures show up by your comment If Members see a thread that violates the Posting Rules, bring it to the attention of the Moderator Team

## For Quick Info

Name

Mobile

E-mail

City

Class

### Find Posts by Topics

Physics

Topics

Mathematics

Chemistry

Biology

Institutes

Parents Corner

Board

Fun Zone

Vertical Limit

Top Contributors
All Time This Month Last Week
1. Bipin Dubey
 Altitude - 16545 m Post - 7958
2. Himanshu
 Altitude - 10925 m Post - 3836
3. Hari Shankar
 Altitude - 9960 m Post - 2185
4. edison
 Altitude - 10815 m Post - 7797
5. Sagar Saxena
 Altitude - 8625 m Post - 8064