I'm doing my CP homework and I'm stuck at this exercise: Read from the keyboard the elements of a 3x3 float matrix. Rearrange the columns so that the sum of
each column's elements is smaller than the sum of the elements of the next column to the right.
What have I done wrong?
>>57950450
>CP Homework
>>57950476
Kek
>>57950450
I'll copy paste the code if that helps:
#include<iostream>
using namespace std;
float sumac(float x[3][3], int c);
void arrange(float x[3][3], int c1, int c2);
void main()
{
int i, j;
float x[3][3];
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
{
cout << "x[" << i << "]" << "[" << j << "]= ";
cin >> x[i][j];
}
for (j = 0; j < 3; j++)
for (i = 0; i < 3; i++)
{
if (sumac(x, i) > sumac(x, i + 1))
arrange(x, i, i + 1);
}
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
cout << x[i][j];
cout << endl;
}
cin.ignore();
cin.get();
}
float sumac(float x[3][3], int c)
{
int i, j;
float csum = 0;
for (j = 0; j<3; i++)
for (i = c; i < 3; j++)
{
csum += x[i][j];
}
return csum;
}
void arrange(float x[3][3], int r1, int r2)
{
int j, temp = 0;
for (j = 0; j < 3; j++)
{
temp = x[r1][j];
x[r1][j] = x[r2][j];
x[r2][j] = temp;
}
}
>>57950450
>CP
Tip submitted thank you
>>57950548
use pastebin dumbass
>>57950945
>>57950476
CP= Computer Programming are you fucking retarded?
>>57950978
Oh
http://pastebin.com/HgBb7aDk
>>57950989
Yeah sure, I'm sure you pedos don't have codewords or anything.
fucking piece of shit
>>57950989
Right, right ;)
No one is going to help you with CP
>>57951029
If you can't figure this out then you are the pseud
>>57950450
>CP homework
>>57950450
>report that CP spam, cunts
>CP
>>57950450
>>57950548
>>57951007
When you compile and run the code, what output do you get?
>>57950450
>prototyping functions in the same file as their declarations
kys
>>57950450
>temp = x[r1][j] (inside arrange)
>assigning float value to an int variable
kys
You need to read Structure and Interpretation of CP.
>>57950450
>not returning anything from arrange
kys
>>57955055
i'm pretty sure this is actually the problem with your code
you're expecting the array x to be different after passing it into the arrange function but that's not how c++ works
you need to also return the modified array and pass it into a variable
put matrix into a vector
sort vector
rebuiild matrix
I think that could work if i understood the problem
>>57950450
>CP homework
Nobody will help you with your pedo homework
>>57950548
>copy pastes code without using
[ c o d e ] your code here[ / c o d e ]
You are fucking filth! Read the sticky
>>57950989
You sound like that guy who thought it meant clown porn
http://pastebin.com/TeygssWf
>>57955325#include<iostream>
using namespace std;
// #define N 3
// don't use magic numbers
// check the sumac, i guess the problem is there. Didn't tested
float sumac(float[3][], int);
void arrange(float[3][], int, int);
int
main(int argc, char* argv[])
{
int i, j;
float x[3][3];
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
cin >> x[i][j];
for (j = 0; j < 3; j++)
for (i = 0; i < 3; i++) {
if (sumac(x, i) > sumac(x, i + 1))
arrange(x, i, i + 1);
}
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++)
cout << x[i][j];
cout << endl;
}
cin.ignore();
cin.get();
}
float
sumac(float x[3][3], int c)
{
float csum = 0;
for (int i=0; i<3; i++)
csum += x[i][c];
return csum;
}
void
arrange(float x[3][3], int r1, int r2)
{
int j, temp = 0;
for (j=0; j<3; j++) {
temp = x[r1][j];
x[r1][j] = x[r2][j];
x[r2][j] = temp;
}
}
put here if some anon is lazy
OP is a faggot
>thinking CP means computer programming
>being this new
Lurk moare m7
>>57950450
sort each row from smallest to biggest number and you are done, fag
>>57955347
how did you do that, how did you post code that was not an image?
>inb4 OP runs a java virus given by fellow posters on this threab
>>57955232
kek