How find the biggest part of column over diagonale of matrix

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

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

The is no such syntax construction as *p=new int [k,k] in C++. Also the type of the left part does not correspond to the type of the right side.

Also I do not see where variable suma was defined
Last edited on

It should be look like that__
#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 ;
}
Codepad show three errors:
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.
This code

nt i,j,k, **mas[i][j];

is already invalid as C++ requires that size of dimensions will be constant expressions.

As for the first error you got I think that you should specify <iostream.h> for your old compiler
Last edited on
Of cause it was better to explain in russian what means "size of dimensions will be constant expressions" but I need to say that i leran not object but problem orienting prohrams so? it would better to write exactly in c.
But at first glance the task is very understandable, and require two or three simple fragments of code. It would be easy for experienced programmer and valuable for beginner. As the practice leads in programming. Especially looking at that the tomorrow is time C(h).
Topic archived. No new replies allowed.