Jump to content

Max sum in matrix A[i][j]

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1
Programming Fan

Programming Fan

    Newbie

  • Members
  • PipPip
  • 25 posts
here is the code i whant to sho me max sum in 3 arrays

the output is
Vnesi gi elementite na matricata A
A[0][0]=1
A[0][1]=2
A[0][2]=3
A[1][0]=4
A[1][1]=5
A[1][2]=6
A[2][0]=7
A[2][1]=8
A[2][2]=9
6 15 24 7 8 9

i want this number 7 8 9 to addition in one and show mw as a max

#include <stdio.h>

void main()


{


int a[3][3];


int i,j,n=3,m=3,s,kraj;


int max[3];




printf("Vnesi gi elementite na matricata A\n");


for (i=0;i<n;i++)


for (j=0;j<n;j++)


{


printf("A[%d][%d]=",i,j);


scanf("%d",&a[i][j]);


}


for (i=0;i<n;i++)


{


s=0;


for (j=0;j<m;j++)


s+=a[i][j];


printf("%3d",s);


}

for (j=0;j<m;j++)

{

max[3]=a[0][j];

for (i=1;i<n;i++)

if (max[3]<a[1][j]) max[3]=a[1][j];

else

if  (max[3]<a[2][j]) max[3]=a[2][j];


printf("%4d",max[3]);

}


scanf ("%d",&kraj);


}



#2
CPD

CPD

    Learning Programmer

  • Members
  • PipPipPip
  • 57 posts
I don't understand your question.

#3
Programming Fan

Programming Fan

    Newbie

  • Members
  • PipPip
  • 25 posts

CPD said:

I don't understand your question.

i want to show me sum of max number in 3 arrays

#4
CPD

CPD

    Learning Programmer

  • Members
  • PipPipPip
  • 57 posts
Got that part, can you be more specific? What do you mean by the max sum? Please show me an example of how you get from an array of numbers to the result.

#5
MeTh0Dz

MeTh0Dz

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,119 posts
Your representation of arrays is wrong.

All arrays, including those of the multidimensional variety are linear.

#6
Programming Fan

Programming Fan

    Newbie

  • Members
  • PipPip
  • 25 posts

CPD said:

Got that part, can you be more specific? What do you mean by the max sum? Please show me an example of how you get from an array of numbers to the result.

the output is
Vnesi gi elementite na matricata A
A[0][0]=1
A[0][1]=2
A[0][2]=3
A[1][0]=4
A[1][1]=5
A[1][2]=6
A[2][0]=7
A[2][1]=8
A[2][2]=9
6 15 24

6 is sum of first array; 15 is sum of second array and 24 is sum of third array for this numbers.. now i whant the programm to show me maximum number in this case 24 output like this "Maximum number is 24" and for others numbers "Maximum number is n"

#7
CPD

CPD

    Learning Programmer

  • Members
  • PipPipPip
  • 57 posts
Ok, how does your code not do that right now?

#8
Programming Fan

Programming Fan

    Newbie

  • Members
  • PipPip
  • 25 posts

CPD said:

Ok, how does your code not do that right now?


i just whant the maximum not others

output Maximum number is ....

#9
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,713 posts
1) Start with a variable called greatest set to the maximum negative value for ints.
2) Add the values up in a column.
3) Compare the sum with the value of greatest. If the sum is greater, then set greatest equal to that sum. Otherwise, continue.
4) For each column, repeat steps 2-4.
5) Print out greatest.

#10
Programming Fan

Programming Fan

    Newbie

  • Members
  • PipPip
  • 25 posts

dargueta said:

1) Start with a variable called greatest set to the maximum negative value for ints.
2) Add the values up in a column.
3) Compare the sum with the value of greatest. If the sum is greater, then set greatest equal to that sum. Otherwise, continue.
4) For each column, repeat steps 2-4.
5) Print out greatest.

Got that part, can you be more specific?

can you give me an excample in my code

#11
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,713 posts
I won't do your homework for you. I believe I was quite clear with what you need to do.

#12
Programming Fan

Programming Fan

    Newbie

  • Members
  • PipPip
  • 25 posts
ok thanks anyway :)