# How to find the biggest column of the matrix (higher of main diagonale)

This is a discussion on How to find the biggest column of the matrix (higher of main diagonale) within the C Programming forums, part of the General Programming Boards category; Here is the draft of code that i desighned/ Of cause it has a several mistake. But would you be ...

1. ## How to find the biggest column of the matrix (higher of main diagonale)

Here is the draft of code that i desighned/ Of cause it has a several mistake. But would you be pleased to corect it a few to make it workable. My task is here to create the matrix, allocate the dinamic memory for it, and to find the biggest sum of the column elements that is located over main diagonale. So main points is correct memory allocation, and the sorting to the biggest sum of column higher than diagonale.

2. incorrect input

3. ## code

Code:
``` #include<iostream>
#include<conio.h>#include<time.h>using namespace std;int main(){    int i,j,k, **pd;	printf("Vvedit  rozmirnist matryci:\n");	scanf("%d", &k);    *p=new int [k,k]	³f (p==NULL) {    printf("\n Allocation Error\n"};    exit (1);	for (i=0; i<k; i++)	{		for (j=0; j<k; j++)		{			scanf("%d",&mas[i][j]);			printf("%d",mas[i][j]);		}        }     for (j=0; j<k; j++)     {         suma[j]=0         if j>i         suma[j]+=mas[i][j]         if (suma[j] < suma[j+1])      {	int temp;	temp = suma[j];	suma[j] = m[j+1];	suma[j+1] = temp;      }     }	printf ("%i",suma[j]);        getch();	return 0 ;}```

4. Edit your post so it isn't all on one line.

5. I think we have a new Turbo C++ Poster.

Hint: Any code with "using namespace std;" is C++ not C code.

Tim S.

6. ## 1

If you about "Vvedit rozm.."-it is about the size of matrix in my local language. I forget it to change. The **pd should be also be changed simply by *p. Or maybe it should be without pointers. So i need correctly allocate memory for two dimensional matrix. Then to display it. To check if the first part is correct. And eventually to find biggest part of column over main diagonale. This is my task. I recommend not compare with any universe as the newbies in programming has such errors it is common. But the main to resolve it.

7. Well until you post correctly formatted code (your native language in text strings doesn't matter so much), nobody is going to help.

Code:
```int main ( ) {
cout << "hello" << endl;
return 0;
}```
See how this is nicely formatted over many lines - as opposed to your 1-line mess.

8. ## It should be look like that__

Code:
```#include<iostream>
#include<conio.h>
#include<time.h>
int main()
{
int i,j,k, **mas[i][j];
printf("Enter matrix size\n");
scanf("%d", &k);
*mas[i][j]=new int [k*k]
if (p==NULL) {
printf("\n Allocation Error\n"};
exit (1);
for (i=0; i<k; i++)
{
scanf("%d",&mas[i][j]);
}
for (i=0; i<k; i++)
{
printf("%d",&mas[i][j]);
}
suma[j]=0;
for (j=0; j<k; j++)
{
for (i<j+1; i<k; i++)
{
suma[j]+=mas[i][j]
}
}

{
int temp = suma[j];
suma[j] = m[j+1];
suma[j+1] = temp;
}
}
printf ("%i",suma[j]);
getch();
return 0 ;
}```

Line 18(for (i=0; i<k; i++)
{
printf("%d",&mas[i][j]);--opposite "{"): error: iostream: No such file or directory
Line 17(look at previous ;ine --opposite "for"): error: conio.h: No such file or directory
*mas[i][j]=new int [k*k]---error: 'new' undeclared (first use in this function).
I do not how corectly show matrix-with pointer or double pointer and than how much pointers to show when allocate memory. This code without allocation memory display typed matrix. Then I need to find the sum of the columns above main diagonale. I do not know if that corect way to do it my code. But more important is how to save this one-size masive of sum-(suma[j])-also in dynamic memory-and when get correct sum--only to chose the biigest one by buble method. So know the task should be easy for experienced programmer--but not for me. What you can reccoment to change here to compile and run here.

10. Also here -> How find the biggest part of column over - C++ Forum

> #include<iostream>
This is C++, but you're compiling C

> #include<conio.h>
This is obsolete, and likely not present in your new compiler.

> int i,j,k, **mas[i][j];
i,j are not initialised, so your matrix size is garbage.
Consider starting with
int mas[100][100];
and then limiting the user to a size less than 100.
It will allow you to get the bulk of the work done, and then we can worry about making it use dynamic memory.

> *mas[i][j]=new int [k*k]
new is from C++.

> printf("\n Allocation Error\n"};
What's that closing brace at the end of this line?

11. Originally Posted by Salem
Also here -> How find the biggest part of column over - C++ Forum

> #include<iostream>
This is C++, but you're compiling C

> #include<conio.h>
This is obsolete, and likely not present in your new compiler.

> int i,j,k, **mas[i][j];
i,j are not initialised, so your matrix size is garbage.
Consider starting with
int mas[100][100];
and then limiting the user to a size less than 100.
It will allow you to get the bulk of the work done, and then we can worry about making it use dynamic memory.

> *mas[i][j]=new int [k*k]
new is from C++.

> printf("\n Allocation Error\n"};

What's that closing brace at the end of this line?
Thank you for your notes. They are valuable. But how correctly initialize with malloc two-dimension massive. I have an example, but it is specially malformed in tiny way, and it uses pointers that is not obvious for initial time. 2. what about the suma[j] that is the value of sums of colums higher the diagonale. Is it correctly initialised, and should it get also a dynamic memory. Where the values of this is saved then to use it for sorting -but for the biggest value. Cause i need to do this code for tomorrow but others get their ones, cause they got ready code from that who are the masters in the coding a long time.

12. Like I said

Code:
```int mas[100][100] = { { 0 } };
int suma[100] = { 0 };```
and get something which works.

Turning these two arrays into dynamic memory is very easy - once you've done the rest of the work.

13. Allocating a 2D array:

Make a program which has the prototype:
int **AllocIntArray(size_t NumRows, size_t Width);

Basically, get a variable with datatype int**
Allocate an array datatype int* (these are your rows)
Loop through this new array and allocate each pointer with another array with the datatype int (these are your columns)
And then return it from your function

You will also need a free function
void FreeIntArray(int **Array, size_t NumRows);
Loop through each row and free it (int *)
And then free the columns (int **)

It's really easy to do to work out how to do it.

14. ## 1

The allocation is only a part of task. But i don not know low to do it correctly. If it would be not with 2d massive. I think it is too much to use function to do it. I need such memory allocation declaration to use a one element of matrix mas[][]. So i need correct mas=new maybe with maloc. Them p== null. The p is mas. But what view should it be. The next is the correct definition of suma. I think it should be it the loop FOR.-and the comparison with previous suma. Not separately.