Hello
I want to write a program a[m][n];
and then scans for a,b
then delete a row and b column
thank You
Hello
I want to write a program a[m][n];
and then scans for a,b
then delete a row and b column
thank You
Hello, I want to collect my nice programmer salary while you write the actual code for me, for free. Thank you.
That sounds ridiculous, right? Yes, it does. Taking credit while others do the work is ridiculous. Read our homework policy: Announcements - General Programming Boards. Then, post back with a reasonable attempt at solving this yourself, and ask specific questions about where you're stuck. Then we will help you.
that is not a homework sir its just a question of my exam which i could not solve it !
Thank You
please Help me Solving This Question Thank You ...
What can this strange device be?
When I touch it, it gives forth a sound
It's got wires that vibrate and give music
What can this thing be that I found?
We'll give you hints though, my hint is the malloc.h header
let me make it clearer for you ! i said i cant but you say you cant ask it and learn it and please be more polite
no i don,t want to use malloc.h header
Elkvis is right. The point is, we are here to help you learn. Doing the work for you will not help you learn. It will only teach you how to copy other's work. Would you learn how to be a good woodworker by asking people to build cabinets and shelves for you? No. You must learn to use all the tools, create the right joints for the boards, etc. It's okay to have somebody teach you and help you though. To walk you through it. Similarly, you will not become a good programmer by having others write code for you.
If you can't do it all right now, that's fine. We're not asking you for a complete working solution (if you could do that, you wouldn't need our help). We're just asking that you make an honest attempt to do it yourself. Write as much as you can on your own. If there are parts you have difficulty with, ask for specific help on those parts, and we will help you.
If you are really completely lost on working with arrays, to the point that you can't even declare or populate one, then I suggest you return to your class notes and textbook, and some online tutorials to brush up.
Here is some free code to get you started
Code:#include <stdlib.h> int main(void) { /* your code goes here */ return EXIT_SUCCESS; }
If you were going to do it (not with a computer), how would you do it? What steps would you use to remove an item from an array of real objects, based on the row and column that someone gives you?
Write down the steps you would take. Be as specific and verbose as possible. Then translate those steps into C code.
What can this strange device be?
When I touch it, it gives forth a sound
It's got wires that vibrate and give music
What can this thing be that I found?
i have problem in shifting the array numbers and my program do not work !
And I dont want to write program just with simple codes not with any codes that wrote up
Is it the "delete" part that is throwing you off?
You don't actually delete the row or column in a 2D array; you just move the latter part of the data by one element (and, optionally, clear the last row/column). In C, with an array declared as a[rows][columns], each row is consecutive in memory. This means that if you "delete" a column, you must move the latter part of each row. If you "delete" a row, you can do it all at once. The memmove() function works well for moving parts of an array around.
I personally don't use such 2D arrays in practice at all, because I need to be able to dynamically resize and allocate them. The structure I use to describe and manage them typically looks like
where the dataref type is where the actual elements are stored, and each matrix just references the data. This allows multiple views to the same data, and I also use it to track the uses of the data (refcount) so that I don't need to remember which matrix "owns" the data; as long as I properly discard each matrix I use, the data gets freed when it is no longer needed.Code:typedef struct dataref dataref; typedef struct { int rows; int cols; long rowstride; long colstride; TYPE *element; dataref *owner; } matrix; struct dataref { struct dataref *next; long refcount; size_t size; TYPE data[]; };
While the above allows vector and sub-matrix views and even transposes and reflections on the data without modifying it, it does not allow cutting a row or a column out of it. However, if I did need that kind of an interface, I might use something like
Whereas the former version uses constant numbers of elements in the one-dimensional element array to go one element "right" (colstep) or "down" (rowstep), this latter one has offsets for each column and each row stored in separate arrays. This way you can pick any row and/or column order, and skip (and even duplicate) ones if you want to.Code:typedef struct { int rows; int cols; long *row; long *col; TYPE *element; dataref *owner; } matrix;
The point is that even in this form I wouldn't actually "delete" anything; I'd just skip it.
If I wanted to, I could create a copy, a duplicate, that didn't have the rows and/or columns skipped, and then free the original.
It is very important to understand the concepts, and design your solution, rather than cobble together the code via trial and error without really understanding why and how it works.
Sorry but i want code with out any struct or any thing else i want this code just with simple things like :loops
Last edited by thedardwhie; 02-05-2015 at 02:03 PM.
You're not going to just get some code, without making a genuine effort to write the code yourself. In case you're still having trouble with the general concept, here is some more help.
Just to clarify, you have a 2-d array, declared like so
So imagine you have an array like so, deleting the specified row and columnCode:#define NUM_ROWS 5 #define NUM_COLS 5 int array[NUM_ROWS][NUM_COLS];
Which would result in something likeCode:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <-- "delete" this row (row 2, remember arrays start at 0 in C) 16 17 18 19 20 21 22 23 24 25 ^ | delete this column (column 1, remember arrays start at 0 in C)
Where the ?? designates data we no longer care about. We started with a 5x5 array, deleted a row and column, and now have a 4x4 array.Code:1 3 4 5 ?? 6 8 9 10 ?? 16 18 19 20 ?? 21 23 24 25 ?? ?? ?? ?? ?? ??
So, if you notice, all we did is basically move, or copy, data from columns to the right of the deleted column, one column to the left. Similarly, we moved/copied data from rows below the deleted row, one row up. We can just overwrite the data in the row/column to delete, and it gives us the desired array.
You don't have to do this all at once. You can first delete the desired row, then the desired column, or you can do it the other way:
Code:1 2 3 4 5 1 2 3 4 5 1 3 4 5 6 7 8 9 10 6 7 8 9 10 6 8 9 10 11 12 13 14 15 -- delete row 2 --> 16 17 18 19 20 -- delete column 1 --> 16 18 19 20 16 17 18 19 20 21 22 23 24 25 21 23 24 25 21 22 23 24 25 1 2 3 4 5 1 3 4 5 1 3 4 5 6 7 8 9 10 6 8 9 10 6 8 9 10 11 12 13 14 15 -- delete column 1 --> 11 13 14 15 -- delete row 2 --> 16 18 19 20 16 17 18 19 20 16 18 19 20 21 23 24 25 21 22 23 24 25 21 23 24 25
simple enough, for example:
I'll leave implementing the actual code to you thoughCode:int colCount = 10; int rowCount = 10; int **rows = mkRows( &rowCount, &colCount ); // initialise with 10 pointers and 10 elements per array pointed to rmRow( rows, &rowCount, 3 ); // free row then move pointers up 1 rows[9] = mkRow( &colCount ); rows = appendRow( rows, &rowCount ); // loop though looking for empty pointer and use realloc if reach end of loop rows = insertRow( rows, &rowCount, 6 ); // move pointers down 1 then use malloc for new array
EditLate post