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................

Recommended Answers

All 5 Replies

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..

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

#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();
}

is the above program correct???

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.

Be a part of the DaniWeb community

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