[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

I'm doing my CP homework and I'm stuck at this exercise:

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 32
Thread images: 7

File: crop.png (31KB, 418x763px) Image search: [Google]
crop.png
31KB, 418x763px
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?
>>
File: eddy.jpg (5KB, 200x175px) Image search: [Google]
eddy.jpg
5KB, 200x175px
>>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
>>
File: 1471111760523.jpg (113KB, 800x800px) Image search: [Google]
1471111760523.jpg
113KB, 800x800px
>>57950450
>report that CP spam, cunts
>>
File: 1440365996276.jpg (245KB, 947x1205px) Image search: [Google]
1440365996276.jpg
245KB, 947x1205px
>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
>>
File: 37118639_p0.jpg (135KB, 500x500px) Image search: [Google]
37118639_p0.jpg
135KB, 500x500px
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?
>>
>>57955556
>>57955134
>>
File: 1473170281596.gif (3MB, 200x150px) Image search: [Google]
1473170281596.gif
3MB, 200x150px
>inb4 OP runs a java virus given by fellow posters on this threab
>>
>>57955232
kek
Thread posts: 32
Thread images: 7


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.