Day 4 (July 22, 2013) Assignment to be done in class and as exercises. Assignment 1: Write a program in C, using arrays, to generate a magic square of odd order. A magic square of order N where N is an odd number has as its entries the numbers 1, 2, ..., N^2 such that the sum of the numbers in the rows is equal to the sum of the numbers in the columns is equal to the sum of the numbers in the principal diagonals. A magic square of order 3 is as follows: 8 1 6 3 5 7 4 9 2 and a magic square of order 5 is as follows: 17 24 01 08 15 23 05 07 14 16 04 06 13 20 22 10 12 19 21 03 11 18 25 02 09 The algorithm to generate a magic square is as follows: Start by writing a 1 in the middle location of the top row. We then write successive integers in a top-right fashion with wrap around if we go out of bounds. The steps are explicitly as follows: ==> When this top-right movement results in a location outside the boundaries of the square, we place the new number at the opposite end of the row or column that would contain the new number, if the rows and columns were not bounded. ==> If the square is already occupied, place the new number directly below the current one. Assignment 2: If you have done the above, then redo it using pointer to pointer and dynamic allocation of arrays. Assignment 3: Write a C program to do the following. (a) Take as input two positive integers (say n1 and n2) from the user. Allocate dynamically A and B, two one-dimensional arrays of integers, of sizes n1 and n2, respectively. Next, allocate a two-dimensional matrix C of size n1Xn2. Fill in C as C[i][j]=A[i]+B[j]; print C properly. Assignment 4: Write a C program that takes as input two positive numbers -- row, col, and allocates space dynamically for two arrays A and B using pointer to pointer. Add matrices A and B to generate another matrix C. Print the matrix C properly. Assignment 5: Write a C program to do the following. (a) Take as input two positive integers (say n1 and n2) from the user. Allocate A and B, two one-dimensional arrays of chars, of sizes n1 and n2, respectively. Read two input strings -- one in A and the other in B. (i) Find whether string B occurs in A. It can occur both in forward or reverse direction. As an example, let A be "abracadabra" and B be "raca", then B occurs in A in forward direction. If B is "bada", then B occurs in A in reverse fashion. (ii) Concatenate the two strings A and B into a string C and print it. ------------------------------------------------------------------------ At the top of each of your program files, add the following. If you are writing multi-file programs, then each file should have it. /*------------------------------------------------------------------ Name: Roll Number: Date of Submission: Deadline date: Program description: Acknowledgements: --------------------------------------------------------------------*/