| | |
please check for me the error and tell me~~ thx!
![]() |
•
•
Join Date: Sep 2007
Posts: 2
Reputation:
Solved Threads: 0
Write a complete C program to perform Matrix operations such as Addition, Subtraction, Multiplication and Transpose according to the user’s choice. The program should display the following menu to the user for them to select one of the five options listed.
------------------
MAIN MENU
------------------
1. MATRIX ADDITION
2. MATRIX SUBTRACTION
3. MATRIX MLTIPLICATION
4. MATRIX TRANSPOSE
5. TO EXIT
---------------------------
Please enter your option <1/2/3/4/5>:
The program should ask the elements of the input matrix or matrices from the user once the required operation is selected. The program should produce a neat output showing both the input and the resultant matrix in matrix form. The program should not be terminated until the user selects the option number 5 (TO EXIT).
THIS IS THE PROGRAM I HAVE DONE.. URGENT PLEASE CORRECT FOR ME! THANKS A LOT!!!!
------------------
MAIN MENU
------------------
1. MATRIX ADDITION
2. MATRIX SUBTRACTION
3. MATRIX MLTIPLICATION
4. MATRIX TRANSPOSE
5. TO EXIT
---------------------------
Please enter your option <1/2/3/4/5>:
The program should ask the elements of the input matrix or matrices from the user once the required operation is selected. The program should produce a neat output showing both the input and the resultant matrix in matrix form. The program should not be terminated until the user selects the option number 5 (TO EXIT).
THIS IS THE PROGRAM I HAVE DONE.. URGENT PLEASE CORRECT FOR ME! THANKS A LOT!!!!
c Syntax (Toggle Plain Text)
#include <stdio.h> /* This header file is for C language */ #include <stdlib.h> /* for the exit() function */ /*Function prototype*/ int matrix_add(int a[3][3],int b[3][3],int result[3][3]); int matrix_subtract(int a[3][3],int b[3][3],int result[3][3]); int matrix_multiply(int a[3][3],int b[3][3],int result[3][3]); int matrix_transpose(int a[3][3], int result[3][3]); int print_matrix(int c[3][3]); int main() { int counter = 0; /* initialize counter */ int option;/*initialize options available*/ int a[3][3]; int b[3][3]; int c[3][3]; /*Print the operations that to be performed*/ printf(" Welcome to User Menu of Matrix Operations\n\n"); printf("--------------------------------------------\n"); printf("\t\tMAIN MENU\n"); printf("--------------------------------------------\n"); printf("\t1. MATRIX ADDITION\n"); printf("\t2. MATRIX SUBTRACTION\n"); printf("\t3. MATRIX MULTIPLICATION\n"); printf("\t4. MATRIX TRANSPOSE\n"); printf("\t5. TO EXIT\n"); printf("--------------------------------------------\n"); printf("Please enter your option <1/2/3/4/5>:\n"); /*Print the input matrices & output*/ { printf("\nMatrix 1:\n"); print_matrix(a); printf("\nMatrix 2:\n"); print_matrix(b); printf("\nResult:\n"); print_matrix(c); } /*As buffer*/ while (counter==0) { /* Get the option*/ if (option==1) { matrix_add(a,b,c); } else if (option==2) { matrix_subtract(a,b,c); } else if (option==3) { matrix_multiply(a,b,c); } else if (option==4) { matrix_transpose(a,c); } else { exit( 1 ); } /*Get the input for two matrices*/ /*Suppose the option is transpose, the input is one matrice*/ /*Switch case for each operation*/ switch (matrix_operations) { case 1:/*addition function*/ { printf("Enter elements of Matrix 1:\n"); scanf("%d",& int a[3][3]); printf("Enter elements of Matrix 2:\n"); scanf("%d",& int b[3][3]); matrix_add(a,b,c) } break; case 2:/*subtraction function*/ { printf("Enter elements of Matrix 1:\n"); scanf("%d",& int a[3][3]); printf("Enter elements of Matrix 2:\n"); scanf("%d",& int b[3][3]); matrix_subtract(a,b,c) } break; case 3:/*multiplication function*/ { printf("Enter elements of Matrix 1:\n"); scanf("%d",& int a[3][3]); printf("Enter elements of Matrix 2:\n"); scanf("%d",& int b[3][3]); matrix_multiply(a,b,c) } break; case 4:/*transpose function*/ { printf("Enter elements of Matrix 1:\n"); scanf("%d",& int a[3][3]); matrix_transpose(a,c) } break; default: { printf("End of Program!\n"); exit( 1 ); } } system("pause"); return 0; } /*Function definition*/ int matrix_add(int a[3][3], int b[3][3], int result[3][3]) { int i, j; for(i=0; i<3; i++) { for(j=0; j<3; j++) { result[i][j] = a[i][j] + b[i][j]; } } return (a+b); } int matrix_subtract(int a[3][3],int b[3][3], int result[3][3]) { int i,j; for (i=0;i<3;i++) { for(j=0;j<3;j++) { result[i][j]= a[i][j]- b[i][j]; } } return (a-b); } int matrix_multiply(a[3][3],b[3][3],int result[3][3]) { int i,j,k; { for (i = 0; i < n; i++) for (j = 0; j < n; j++) for (k = a[i][j] = 0; k < n; k++) { result[i][j] += b[i][k] * c[k][j]; } } return (a*b); } int matrix_transpose(int a[3][3],int result[3][3]) { int i,j,n,temp; { for (i = 0; i < n-1; i++) for (j = i+1; j < n; j++) { temp = b[i][j]; b[i][j] = b[j][i]; b[j][i] = temp; } } return (b); } int print_matrix(int c[3][3]) { int i, j; for (i=0; i<3; i++) { for (j=0; j<3; j++) { printf("%d\t", a[i][j]); } printf("\n"); } } }
Last edited by Ancient Dragon; Sep 11th, 2007 at 8:28 pm. Reason: add code tags
Looks like a direct rip-off of this post as well, right down to the syntax errors.
http://www.daniweb.com/forums/post428174-13.html
Almost certainly in the same class, could even be the same person registering with a new account hoping the "clean" noob status will garner a bit of extra sympathy / effort on our part.
http://www.daniweb.com/forums/post428174-13.html
Almost certainly in the same class, could even be the same person registering with a new account hoping the "clean" noob status will garner a bit of extra sympathy / effort on our part.
![]() |
Similar Threads
- Error message upon start up (Windows NT / 2000 / XP)
- Error Opening Project (ASP.NET)
- Stmgr error in msvcrt.dll (Windows 95 / 98 / Me)
- CRC error when copying MP3 from Cd (Windows NT / 2000 / XP)
- Windows XP Startup Problem (Windows NT / 2000 / XP)
- hardware/re-boot problem... (Windows NT / 2000 / XP)
- Computer shutsdown when encoding (Troubleshooting Dead Machines)
- Sendmail and SquirrelMail problem. (Linux Servers and Apache)
- file unable to open (C++)
Other Threads in the C Forum
- Previous Thread: Trying to solve this problem
- Next Thread: Need help with Data Structure and Algorithms
| Thread Tools | Search this Thread |
adobe ansi api array asterisks binarysearch calculate centimeter changingto char convert copyanyfile copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile createprocess() csyntax database directory fflush file fork forloop frequency givemetehcodez global grade graphics gtkgcurlcompiling hacking highest histogram homework i/o inches infiniteloop input interest iso kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate looping loopinsideloop. lowest match meter microsoft mysql number open opendocumentformat owf pattern pdf performance posix power probleminc process program programming pyramidusingturboccodes radix read recv repetition research reversing scanf scheduling segmentationfault send sequential socket socketprograming socketprogramming stack standard string suggestions systemcall threads turboc unix user variable voidmain() wab win32api windows.h windowsapi






