Like Tree1Likes
  • 1 Post By Click_here

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. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    13

    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. #2
    Registered User
    Join Date
    Jan 2013
    Posts
    13
    incorrect input

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    13

    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. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,338
    Edit your post so it isn't all on one line.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    2,372
    I think we have a new Turbo C++ Poster.

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

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  6. #6
    Registered User
    Join Date
    Jan 2013
    Posts
    13

    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. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,338
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    Jan 2013
    Posts
    13

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

  9. #9
    Registered User
    Join Date
    Jan 2013
    Posts
    13
    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.

  10. #10
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,338
    Also here -> How find the biggest part of column over - C++ Forum
    Were you banned? -> http://www.cyberforum.ru/cpp-beginne...ead767474.html

    > #include<iostream>
    This is C++, but you're compiling C
    Try #include <stdio.h> instead.

    > #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?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  11. #11
    Registered User
    Join Date
    Jan 2013
    Posts
    13
    Quote Originally Posted by Salem View Post
    Also here -> How find the biggest part of column over - C++ Forum
    Were you banned? -> http://www.cyberforum.ru/cpp-beginne...ead767474.html

    > #include<iostream>
    This is C++, but you're compiling C
    Try #include <stdio.h> instead.

    > #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. #12
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,338
    Like I said

    Start with
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  13. #13
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,303
    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.
    Fact - Beethoven wrote his first symphony in C

  14. #14
    Registered User
    Join Date
    Jan 2013
    Posts
    13

    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.

  15. #15
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,303
    Here is a tutorial which I think will help you.

    23.2: Dynamically Allocating Multidimensional Arrays
    stahta01 likes this.
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sum of elements of row/column of a matrix
    By Pole in forum C Programming
    Replies: 14
    Last Post: 12-31-2011, 01:50 PM
  2. Change column in matrix
    By plasticstone in forum C Programming
    Replies: 2
    Last Post: 10-22-2011, 10:19 AM
  3. calculate column-wise sum of a matrix in C
    By Raymond2010 in forum C Programming
    Replies: 4
    Last Post: 06-21-2011, 11:21 PM
  4. Replies: 1
    Last Post: 02-21-2010, 12:09 PM
  5. column-major matrix Q....
    By pxleyes in forum C Programming
    Replies: 3
    Last Post: 03-24-2004, 07:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21