please check for me the error and tell me~~ thx!

Reply

Join Date: Sep 2007
Posts: 2
Reputation: anzdyy is an unknown quantity at this point 
Solved Threads: 0
anzdyy anzdyy is offline Offline
Newbie Poster

please check for me the error and tell me~~ thx!

 
0
  #1
Sep 11th, 2007
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!!!!



  1. #include <stdio.h> /* This header file is for C language */
  2. #include <stdlib.h> /* for the exit() function */
  3.  
  4. /*Function prototype*/
  5. int matrix_add(int a[3][3],int b[3][3],int result[3][3]);
  6. int matrix_subtract(int a[3][3],int b[3][3],int result[3][3]);
  7. int matrix_multiply(int a[3][3],int b[3][3],int result[3][3]);
  8. int matrix_transpose(int a[3][3], int result[3][3]);
  9. int print_matrix(int c[3][3]);
  10.  
  11. int main()
  12. {
  13. int counter = 0; /* initialize counter */
  14. int option;/*initialize options available*/
  15. int a[3][3];
  16. int b[3][3];
  17. int c[3][3];
  18.  
  19. /*Print the operations that to be performed*/
  20.  
  21. printf(" Welcome to User Menu of Matrix Operations\n\n");
  22. printf("--------------------------------------------\n");
  23. printf("\t\tMAIN MENU\n");
  24. printf("--------------------------------------------\n");
  25. printf("\t1. MATRIX ADDITION\n");
  26. printf("\t2. MATRIX SUBTRACTION\n");
  27. printf("\t3. MATRIX MULTIPLICATION\n");
  28. printf("\t4. MATRIX TRANSPOSE\n");
  29. printf("\t5. TO EXIT\n");
  30. printf("--------------------------------------------\n");
  31. printf("Please enter your option <1/2/3/4/5>:\n");
  32.  
  33. /*Print the input matrices & output*/
  34. {
  35. printf("\nMatrix 1:\n");
  36. print_matrix(a);
  37.  
  38. printf("\nMatrix 2:\n");
  39. print_matrix(b);
  40.  
  41. printf("\nResult:\n");
  42. print_matrix(c);
  43. }
  44.  
  45.  
  46. /*As buffer*/
  47.  
  48. while (counter==0)
  49. {
  50. /* Get the option*/
  51. if (option==1)
  52. {
  53. matrix_add(a,b,c);
  54. }
  55. else if (option==2)
  56. {
  57. matrix_subtract(a,b,c);
  58. }
  59. else if (option==3)
  60. {
  61. matrix_multiply(a,b,c);
  62. }
  63. else if (option==4)
  64. {
  65. matrix_transpose(a,c);
  66. }
  67. else
  68. {
  69. exit( 1 );
  70. }
  71.  
  72. /*Get the input for two matrices*/
  73. /*Suppose the option is transpose, the input is one matrice*/
  74.  
  75.  
  76. /*Switch case for each operation*/
  77. switch (matrix_operations)
  78.  
  79. {
  80. case 1:/*addition function*/
  81. {
  82. printf("Enter elements of Matrix 1:\n");
  83. scanf("%d",& int a[3][3]);
  84. printf("Enter elements of Matrix 2:\n");
  85. scanf("%d",& int b[3][3]);
  86. matrix_add(a,b,c)
  87. }
  88. break;
  89. case 2:/*subtraction function*/
  90. {
  91. printf("Enter elements of Matrix 1:\n");
  92. scanf("%d",& int a[3][3]);
  93. printf("Enter elements of Matrix 2:\n");
  94. scanf("%d",& int b[3][3]);
  95. matrix_subtract(a,b,c)
  96. }
  97. break;
  98. case 3:/*multiplication function*/
  99. {
  100. printf("Enter elements of Matrix 1:\n");
  101. scanf("%d",& int a[3][3]);
  102. printf("Enter elements of Matrix 2:\n");
  103. scanf("%d",& int b[3][3]);
  104. matrix_multiply(a,b,c)
  105. }
  106. break;
  107. case 4:/*transpose function*/
  108. {
  109. printf("Enter elements of Matrix 1:\n");
  110. scanf("%d",& int a[3][3]);
  111. matrix_transpose(a,c)
  112. }
  113. break;
  114. default:
  115. {
  116. printf("End of Program!\n");
  117. exit( 1 );
  118. }
  119.  
  120. }
  121.  
  122. system("pause");
  123. return 0;
  124. }
  125.  
  126. /*Function definition*/
  127. int matrix_add(int a[3][3], int b[3][3], int result[3][3])
  128. {
  129. int i, j;
  130. for(i=0; i<3; i++)
  131. {
  132. for(j=0; j<3; j++)
  133. {
  134. result[i][j] = a[i][j] + b[i][j];
  135. }
  136. }
  137. return (a+b);
  138. }
  139.  
  140. int matrix_subtract(int a[3][3],int b[3][3], int result[3][3])
  141. {
  142. int i,j;
  143. for (i=0;i<3;i++)
  144. {
  145. for(j=0;j<3;j++)
  146. {
  147. result[i][j]= a[i][j]- b[i][j];
  148. }
  149. }
  150. return (a-b);
  151. }
  152.  
  153. int matrix_multiply(a[3][3],b[3][3],int result[3][3])
  154. {
  155. int i,j,k;
  156. {
  157. for (i = 0; i < n; i++)
  158. for (j = 0; j < n; j++)
  159. for (k = a[i][j] = 0; k < n; k++)
  160. {
  161. result[i][j] += b[i][k] * c[k][j];
  162. }
  163. }
  164. return (a*b);
  165. }
  166.  
  167. int matrix_transpose(int a[3][3],int result[3][3])
  168. {
  169. int i,j,n,temp;
  170. {
  171. for (i = 0; i < n-1; i++)
  172. for (j = i+1; j < n; j++)
  173. {
  174. temp = b[i][j];
  175. b[i][j] = b[j][i];
  176. b[j][i] = temp;
  177. }
  178. }
  179. return (b);
  180. }
  181. int print_matrix(int c[3][3])
  182. {
  183. int i, j;
  184. for (i=0; i<3; i++)
  185. {
  186. for (j=0; j<3; j++)
  187. {
  188. printf("%d\t", a[i][j]);
  189. }
  190. printf("\n");
  191. }
  192. }
  193. }
Last edited by Ancient Dragon; Sep 11th, 2007 at 8:28 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,541
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: please check for me the error and tell me~~ thx!

 
0
  #2
Sep 11th, 2007
>URGENT PLEASE CORRECT FOR ME! THANKS A LOT!!!!
You'll get better results if you describe the problems that you're having.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,050
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 331
Moderator
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: please check for me the error and tell me~~ thx!

 
0
  #3
Sep 11th, 2007
And this has exactly what to do with Linux?
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: please check for me the error and tell me~~ thx!

 
0
  #4
Sep 12th, 2007
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC