Your program will have a 3x3 array. The user will input the sum of each row and each column. Then the user will input 3 values and store them anywhere, or any location or index, temporarily in the array. Your program will supply the remaining six (6) values and determine the exact location of each value in the array.

Example:
Input: Sum of row 1: 6
Sum of row 2: 15
Sum of row 3: 24
Sum of column 1: 12
Sum of column 2: 15
Sum of column 3: 18
Value 1: 3
Value 2: 5
Value 3: 6

Output: Sum of Row
1 2 3 6
4 5 6 15
7 8 9 24
Sum of Column
12 15 18

Note: Your program will not necessary sort the walues in the array

Thanks..

Schol-R-LEA commented: Posting a simple request to solve a homework problem is unacceptable, especially as one's first post. -1

We don't do homework problems for lazy students.

Realize Narue's position: this place (and others like it) draw many, many leeches. By leech I mean people who would rather copy and paste their homework into a forum and wait for a reply than attempt to do any work for themselves. The typical sign of this is a post …

And i really don't think that THIS IS THE FRIENDLIEST IT Community. Starting off with your RUDE REPLY

Trust me, had you posted to, say, DevShed with the attitude you've displayed, you would have seen what a rude reply looks like. You should thank us for our grandmotherly …

## All 10 Replies

We don't do homework problems for lazy students.

I Ain't lazy. its just that i can't code it myself.i've tried for many days but to no avail. >.<

And i really don't think that THIS IS THE FRIENDLIEST IT Community. Starting off with your RUDE REPLY

commented: Go away, or post what you tried, if you really have made an effort that is -4

Realize Narue's position: this place (and others like it) draw many, many leeches. By leech I mean people who would rather copy and paste their homework into a forum and wait for a reply than attempt to do any work for themselves. The typical sign of this is a post that is verbatim the assignment to be completed void of any effort on the part of the poster. Most times it is the first (or one of the first) posts of the person asking for help.

Your post was your first, the content of that post is a copy of the assignment you are to hand in and you provide no indication that you have done anything on your own. What are we supposed to think?

If you'd like help with a particular aspect of the assignment you are having trouble with, post the code you have and describe your problem.

And i really don't think that THIS IS THE FRIENDLIEST IT Community.

I'm sorry we didn't spoon feed you immediately. Oh wait, no, I'm not. If you had read our rules, you would know that we require proof of effort before helping with homework. You've given no such proof, so you get no help.

And i really don't think that THIS IS THE FRIENDLIEST IT Community. Starting off with your RUDE REPLY

Trust me, had you posted to, say, DevShed with the attitude you've displayed, you would have seen what a rude reply looks like. You should thank us for our grandmotherly kindness in setting you back on the path to good coding.

That having been said, I should say that you might be able to redeem yourself in the eyes of the forum by posting the code you've already written (properly, using [CODE tags) and asking specific questions about the problems you are facing with it. While we may seem rude, we do want to help you solve the problem; however, there is a world of difference between 'helping you program better' and 'helping you get a passing grade'. We want to do the former, if for no better reason than that we may have to work with you someday, while the latter is of little real consequence to us no matter how important it may be to you.

Has anyone actually read the assignment he posted??? It makes absolutely no sense.

>>The user will input the sum of each row and each column.
So the programmer creates a 3x3 array. How is the user supposed to know what the sum of the rows and columns are -- the array at that point just contains some random values, whatever happened to be on the stack at the time the array is created.

>>Then the user will input 3 values and store them anywhere, or any location or index,

Just more nonsense. So what if I store it in `array[rand()][rand()];` That's not very likely to work.

``````#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

#include <time.h>

#include <dos.h>

main()

{int array={0};

int sumRow, sumCol;

int x=0, y=0;

int RandRow=5, RandCol=5;

int cntr=0;

int diffRow={0}/*, diffCol={0}*/;

int ZeroCounter[x]=0;

clrscr();

for(y=0; y<2; y++)

{if(y==0)

for(x=0; x<3; x++)

{printf("Please input the sum of row %d: ", x+1);

scanf("%d", &sumRow[x]);

}

else

for(x=0; x<3; x++)

{printf("Please input the sum of column %d: ", x+1);

scanf("%d", &sumCol[x]);

}

}

randomize();

for(x=0; x<3; x++)

{RandRow=5;

RandCol=5;

while(cntr==0)

{while(RandRow>=3)

RandRow=rand() % 10;

while(RandCol>=3)

RandCol=rand() % 10;

/*delay(1000);

printf("\n%d %d\n", RandRow, RandCol);*/

if(array[RandRow][RandCol]==0)

{printf("Please input value %d: ", x+1);

scanf("%d", &array[RandCol][RandRow]);

cntr=1;

break;

}

}

cntr=0;

}

for(x=0; x<3; x++)

{cntr=0;

for(y=0; y<3; y++)

cntr=cntr+array[x][y];

diffRow[x]=sumRow[x]-cntr;

}

/* for(x=0; x<3; x++)

{cntr=0;

for(y=0; y<3; y++)

cntr=cntr+array[y][x];

diffCol[x]=sumCol[x]-cntr;

}*/

for(x=0; x<3; x++)

printf("%d %d\n", diffRow[x]/*, diffCol[x]*/);

for(x=0; x<3; x++)

{cntr=0;

for(y=0; y<3; y++)

if(array[x][y]==0)

cntr++;

ZeroCounter[x]=cntr;

}

for(x=0; x<3; x++)

{for(y=0; y<3; y++)

if(ZeroCounter[x]==1&&array[x][y]==0)

{array[x][y]=diffRow[x];

break;

}

else

if(ZeroCounter[x]==2)

for(x=0; x<3; x++)

{printf("\n");

for(y=0; y<3; y++)

printf("%d\t", array[x][y]);

}

getch();

return 0;

}}``````

sorry for what i've done..but guys..i really need your help.. i don't know whats the problem in this code...

Could you tell us something about the problem, e.g., what error messages you're getting, how it is misbehaving, and so on?

I can tell you a few of the problems I see off the top of my head. First off, the initializers for array and ZeroCounter are incorrect; also, you defined the index of ZeroCounter as 'x', which won't work the way you expect - the value of an array index has to be a compile-time constant. Here are two declarations which ought to work:

``````int array = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
int ZeroCounter = {0, 0, 0};``````

Also, there is no standard function named randomize() in C. What you need to do is first call srand() with some suitably unpredictable seed value (the current time should be sufficient for this case), then call rand() to get the actual random numbers.

Here is a quickly modified version of your code, with the changes I suggested; I hope you don't mind that I re-formatted the code according to a more typical indent style, but I think most people here will be able to follow it more easily than your more idiosyncratic style.

``````#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()

{
int array = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
int sumRow, sumCol;
int x=0, y=0;
int RandRow=5, RandCol=5;
int cntr=0;
int diffRow = {0}/*, diffCol={0}*/;
int ZeroCounter= {0, 0, 0};

srand(time(NULL));

for(y=0; y<2; y++)
{
if(y==0)
for(x=0; x<3; x++)
{
printf("Please input the sum of row %d: ", x+1);
scanf("%d", &sumRow[x]);
}
else
for(x=0; x<3; x++)
{
printf("Please input the sum of column %d: ", x+1);
scanf("%d", &sumCol[x]);
}
}

for(x=0; x<3; x++)
{
RandRow=5;
RandCol=5;
while(cntr==0)
{
while(RandRow>=3)
RandRow=rand() % 10;

while(RandCol>=3)
RandCol=rand() % 10;

/*delay(1000);
printf("\n%d %d\n", RandRow, RandCol);*/

if(array[RandRow][RandCol]==0)
{
printf("Please input value %d: ", x+1);
scanf("%d", &array[RandCol][RandRow]);
cntr=1;
break;
}
}
cntr=0;
}

for(x=0; x<3; x++)
{
cntr=0;
for(y=0; y<3; y++)
cntr=cntr+array[x][y];
diffRow[x]=sumRow[x]-cntr;
}

for(x=0; x<3; x++)
printf("%d %d\n", diffRow[x]/*, diffCol[x]*/);

for(x=0; x<3; x++)
{
cntr=0;
for(y=0; y<3; y++)
if(array[x][y]==0)
cntr++;

ZeroCounter[x]=cntr;
}

for(x=0; x<3; x++)
{
for(y=0; y<3; y++)
if(ZeroCounter[x]==1&&array[x][y]==0)
{
array[x][y]=diffRow[x];
break;
}

else
if(ZeroCounter[x]==2)
for(x=0; x<3; x++)
{
printf("\n");
for(y=0; y<3; y++)
printf("%d\t", array[x][y]);
}

}

return 0;
}``````

I expect that there are still issues with this, but it's frankly hard to tell given the poorly-worded problem statement. You'd know better than we would if this fits what you're aiming at.

As for how you got saddled with an archaic compiler like Turbo C, well, I know that there are a lot of professors out there who are using it, more's the pity, but I will say that if you have any choice in the matter, upgrade to a modern compiler such as Visual C++ Express or Code::Blocks (which is an IDE on top of GCC, technically speaking, but whatever). There are enough free C/C++ compilers around that there is no real reason to stick with one that is older than you are.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.