




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





Problem # Assumptions:
Write a C program that will read in a string of n characters (1 character at a time) then use a recursive function to reverse the string of characters and place them in to a second array in the reverse order from the original input order, and finally use another function to determine if the original string was a palindrome (a word or string that reads the same forward and backward). Your program should prompt the user for the original string, print out this string as well as the reverse of the string, and finally should print a message indicating if the string is a palindrome. You will write programs in C to solve the following problems. Each program is a stand- alone program, so the disk you submit will contain three separate programs.
Assumptions:
for (i = 0; i < rows-1; i++) for (j = i+1; j < columns; j++){ temp = A[i][j]; A[i][j] = A[j][i]; A[j][i] = temp; } Example Execution: Enter the row dimension of matrix A: 3 Enter the column dimension of matrix A: 3 Enter the row dimension of matrix B: 3 Enter the column dimension of matrix B: 3 Matrix A is: 2 4 5 3 1 4 2 6 8 Matrix B is: 3 4 1 2 5 1 2 6 2 Sum of A + B is: 5 8 6 5 6 5 4 12 10 Product of A B is: 24 58 16 19 41 12 34 86 24 Transpose of Matrix A is: 2 3 2 4 1 6 5 4 8 Transpose of Matrix B is: 3 2 2 4 5 6 1 1 2 Transpose of Matrix C is: 24 19 34 58 41 86 16 12 24 Matrix Operations Explained
Matrix Addition for (i = 0; i < n; i++) for (j = 0; j < n; j++) A[i][j] = B[i][j] + C[i][j]; In general, matrix addition is defined only for two matrices of the same size (although they do not need to be square). Thus A[n,m] = B[n,m] + C[n,m] with addition defined as: ^ ^ (b[n, 1 ] c[n, 1 ]) b[n, 2 ] c[n, 2 ]) ...(b[n, m (b[ 2 , 1 ] c[ 2 , 1 ]) b[ 2 , 2 ] c[ 2 , 2 ]) ...(b[ 2 , m (b[ 1 , 1 ] c[ 1 , 1 ]) b[ 1 , 2 ] c[ 1 , 2 ]) ...(b[ 1 ,m ] A [n,m ] Example: Martix B 2 3 2 1 4 6 3 2 2 Matrix C 4 3 2 1 3 3 2 2 4 Matrix C = A[n,m] + B[n,m] 2 + 4 = 6 3 + 3 = 6 2 + 2 = 4 1 + 1 = 2 4 + 3 = 7 6 + 3 = 9 3 + 2 = 5 2 + 2 = 4 2 + 4 = 6 Matrix Multiplication for (i = 0; i < n; i++) for (j = 0; j < n; j++) for (k = A[i][j] = 0; k < n; k++) A[i][j] += B[i][k] * C[k][j];
Matrix Transposition for (i = 0; i < n-1; i++) for (j = i+1; j < n; j++){ temp = A[i][j]; A[i][j] = A[j][i]; A[j][i] = temp; } In general, the transpose of a matrix is the matrix that results from the interchanging of its rows and columns. Given a matrix B, its transpose is generally denoted as BT. Example: Matrix B 2 3 2 1 4 6 3 2 2 Matrix BT 2 1 3 3 4 2 2 6 2 Matrix A = B C (24 + 31 + 22) (23 + 33 + 22) (22 + 33 + 24) (14 + 41 + 62) (13 + 43 + 62) (12 + 43 + 64) (34 + 21 + 22) (33 + 23 + 22) (32 + 23 + 2*4) Thus Matrix A is: 15 19 21 20 27 38 18 19 20
Matrix Transposition for (i = 0; i < n-1; i++) for (j = i+1; j < n; j++){ temp = A[i][j]; A[i][j] = A[j][i]; A[j][i] = temp; } In general, the transpose of a matrix is the matrix that results from the interchanging of its rows and columns. Given a matrix B, its transpose is generally denoted as BT. Example: Matrix B 2 3 2 1 4 6 3 2 2 Matrix BT 2 1 3 3 4 2 2 6 2