You are here:

C/new question

Advertisement


Question
QUESTION: Write a program in C that does the following.
1. Creates a 2-D array of integers of size 4 x 4, say arr[4][4]
2. Takes input from the user for the 2-D array
3. Rearranges elements of the array such that arr[i][j] <= arr[k][m] whenever
i+j < k+m. Your algorithm must have O(N log N) time complexity in the worst-
case, where N is the number of elements in the 2-D array. Note that here
N=16.
4. Prints the new contents of the array.


ANSWER: Edit November 2
Hello Pradeep
Sorry, I forgot that you are using C, and not C++. In that case, you will need to ignore what I said about classes and overloading the indexing operator. That applies to C++ only. However, everything I said about the lookup table is still true, You just need to implement it with C functions and C arrays, instead of a class. I changed the document to show how to use the lookup table with C.


Hello Pradeep

Thank you for the thought provoking problem.

Please read my answer to you here

https://docs.google.com/document/edit?id=1m1avN19kwdizwY25c_DkM-m5egONZ6u2xfT4jgHuBUw&hl=en&authkey=CNinudcE

Kindest regards
Zlatko

---------- FOLLOW-UP ----------

QUESTION:          €
Your program must do the following.
1. Read from a file the coefficients and exponents of two polynomials. The filename is your choice. For
example, the two polynomials mentioned above must be stored in the file in the following comma
separated value (CSV) format. Note that we simply store coefficients and exponents separated by
commas. The extra -1 is a termination symbol which indicates where the information for a particular
polynomial has ended.
4,3,3,1,1,0,-1
1,5,-5,3,2,2,-1
2. Create and store the two polynomials as two linked lists.
3. Ask the user to input whether he wants the two polynomials to be added, subtracted, or multiplied.
Using the “switch” statement, call one of add_poly, subtract_poly, or multiply_poly.
4. Write the coefficients and corresponding exponents of the resulting polynomial in CSV format to an
output file. The choice of file name is yours.
Your program must contain the following functions.
1. Function “add_poly” takes pointers to two linked lists containing polynomials and modifies the first
linked list to contain the sum of the two polynomials stored in the lists. You may not use a third linked list
or an array in this function.
2. Function “subtract_poly” takes pointers to two linked lists and modifies the first linked list to contain the
difference of the two polynomials stored in the lists. You may not use a third linked list or array in this
function.
3. Function “multiply_poly” takes pointers to two linked lists and returns a pointer to a third linked list
containing the result of the multiplication. You may use two additional linked lists in this function, besides
the two input linked lists. You may also use the functions add_poly and subtract_poly in this function.
4. Basic functions to add, delete, and insert nodes in a linked list.


Answer
Hello Pradeep.

How did you manage with the sorted 2D array problem? Was my answer to you helpful or did you find another way to sort the array?

For your new question, you have just given me the problem statement. You have not told me what you are having difficulty with. Please tell me what you don't understand, or show me what part of the code you are having trouble with.

Are you asking me to provide a complete documented solution to you ? I provide help for **free** but complete solutions for a price. Your assignment is quite time consuming, but not difficult. In this case the price is 15 US dollars. You must be able to pay to paypal and you must provide me with an email address in a private question.

If you want free help, then you must provide some effort by at least telling me what you want help with.

Kindest regards
Zlatko

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Zlatko

Expertise

No longer taking questions.

Experience

No longer taking questions.

Education/Credentials
No longer taking questions.

©2012 About.com, a part of The New York Times Company. All rights reserved.