We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- C
- Arrays and Strings
- Dynamic Array in C
- Discussions
Dynamic Array in C
Dynamic Array in C
Sort by
recency
|
406 Discussions
|
Please Login in order to post a comment
In the assigment they missed to tell that you have to allocate the page matrice and the book array :)
I had trouble understanding what to do because the name of the matrix 'total_number_of_pages' (which is the matrix to represent the shelves itself) it not intuitive. Pages are things inside of books.
The problem has poor explanation of why we are using the array 'total_number_of_books', it can be a bit confusing since we can try to use it inside of the matrix, again, because of the name.
Matrix name should be simply 'shelves', and the array name should be something that actually points to its purpouse of being a map to how many books are in each shelf.
include
include
/* * This stores the total number of books in each shelf. / int total_number_of_books;
/* * This stores the total number of pages in each book of each shelf. * The rows represent the shelves and the columns represent the books. / int* total_number_of_pages;
int main() { int total_number_of_shelves; scanf("%d", &total_number_of_shelves);
}
JUST ONE LINE ANSWER AFTER ALLOCATING THE MEMORY FOR BOTH ARRAYS;int main() { total_number_of_books=(int*)calloc(total_number_of_shelves,sizeof(int)); total_number_of_pages=(int**)calloc(total_number_of_shelves,sizeof(int*)); for(int i=0;i total_number_of_pages[i]=(int*)calloc(1100,sizeof(int)); } while (total_number_of_queries--) {
int type_of_query; scanf("%d", &type_of_query);
if (type_of_query == 1) {
int x, y; scanf("%d %d", &x, &y);
* ((totalnumberofpages+x)+((totalnumberofbooks+x))++)=y; *
int main() { int total_number_of_shelves; scanf("%d", &total_number_of_shelves);