We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,996 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

matrix program

can any body tell me a udf program in c++ which accepts a squared integer matrix with odd dimensions(like 33,55....) & display the sum of the middle row and middle column elements.
please help me if you can................

4
Contributors
5
Replies
1 Day
Discussion Span
11 Months Ago
Last Updated
8
Views
arushi.05
Newbie Poster
4 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

When you ask a question, try to write it in a good form.. otherwise you won't get much help. first search yourself on forum, tell us how much have you worked, where are you stuck and things..
no one is going to spoon feed you here..

Humayoon Khan
Newbie Poster
6 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

well as for the "mathametical" question:
if you have 5 rows it shows in c++ as 0-1-2-3-4
so you need to get the '2' row which can be done by just dividing by 2 (5 / 2 =2 - if you are using integers)
another example if there are 3 rows - 0-1-2
3/2 = 1 which is the row number 1 .

as for the c++ programming you have to study on your own

Despairy
Junior Poster
123 posts since Mar 2011
Reputation Points: 10
Solved Threads: 5
Skill Endorsements: 0
#include<iostream.h>
#include<conio.h>
void main()
{
  int a[3][3],i,j,sumr=0,sumc=0;
 clrscr();
 cout<<"enter the array of size 3*3";
 for(i=0;i<3;i++)
 {
     for(j=0;j<3;j++)
     cin>>a[i][j];
     }
for(i==1)
{ 
   for(j=0;j<3;j++)
   sumr+=a[i][j];
   }
 for(i=0;i<3;i++)
 {
    for(j==1)
    sumc+=a[i][j];
    }
cout<<"sum of elements of middle row="<<sumr;
cout<<"sum of elements of middle column="<<sumc;
getch();
}
arushi.05
Newbie Poster
4 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

is the above program correct???

arushi.05
Newbie Poster
4 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Make test cases and test it, have you coded it or not?

For me I would leave out at least the conio, clrscr and getch bit. And how are you reading the 33 or 55 square matrixes when it says input 3x3 matrix?

I can not imagine anybody typing in zillion useless numbers to get result only from middle column and one whole line, so I think input should be without prompting (coming from file through indirection, as this is main program, not function). You only need to save one total for column and one total for the row, two scalar variables.

for(j==1)

This does not make sense.

pyTony
pyMod
Moderator
6,305 posts since Apr 2010
Reputation Points: 879
Solved Threads: 986
Skill Endorsements: 26

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0739 seconds using 2.69MB