Advertisement
vichis_mar

Untitled

Nov 14th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. int *MatrizA;
  5. int *MatrizB;
  6. int primo();
  7. int primo1();
  8. void menu();
  9. void suma(int *x, int *y, int a);
  10. int r[]={0};
  11. int h[]={0};
  12. void resta(int *x, int *y, int a);
  13. void imprimir(int *x, int a);
  14. int main()
  15. {
  16. int M, A, i, x=0, y=0, op;
  17.  
  18.  
  19. printf("Ingresa el numero de renglones por columnas:");
  20. scanf("%i",&M); //columna
  21. A=M*M;
  22.  
  23. //RESERVACION DE A
  24. MatrizA=(float **)malloc(A*sizeof(int*));
  25.  
  26. for(i=0;i<=A-1;i++){
  27. MatrizA[i]=(float *)malloc(A*sizeof(int));
  28. }
  29.  
  30. // MatrizB=(int*)malloc(A*sizeof(int));
  31.  
  32. MatrizB=(float **)malloc(A*sizeof(int*));
  33.  
  34. for(i=0;i<=A-1;i++){
  35. MatrizB[i]=(float *)malloc(A*sizeof(int));
  36. }
  37.  
  38. menu();
  39. scanf("%i",&op);
  40.  
  41. //LLENADO DE LAS MATRICES
  42.  
  43.  
  44. //MATRIZ A
  45.  
  46. for(i=0;i<A+1;i++){
  47. x=primo1();
  48. MatrizA[i]= x;
  49.  
  50. }
  51.  
  52. //MATRIZ B
  53.  
  54. for(i=0;i<A+1;i++){
  55. y=primo1();
  56. MatrizB[i] = y;
  57. }
  58.  
  59.  
  60. switch(op){
  61. case 1:
  62. printf("SUMA");
  63. suma(MatrizA,MatrizB,A);
  64. imprimir(r,A);
  65. break;
  66. case 2:
  67. printf("RESTA:");
  68. resta(MatrizA,MatrizB,A);
  69. imprimir(h,A);
  70. break;
  71. case 3:
  72. printf("MULTIPLICACIÓN:\n");
  73. break;
  74. case 4:
  75. imprimir(MatrizA,A);
  76. imprimir(MatrizB,A);
  77. break;
  78. }
  79.  
  80. }
  81. int primo1(){
  82. int x;
  83. srand(time(NULL));
  84.  
  85. do{x=rand()%(101);
  86.  
  87. if(x%2!=0 && x%3!=0 && x%5!=0 && x%7!=0){
  88. if (x==2 || x==3 || x==5 || x==7){
  89. return x;
  90. }
  91.  
  92. }
  93. else{
  94. x=0;
  95.  
  96. }
  97. }while(x==0);
  98. return x;
  99. }
  100.  
  101. int primo(){
  102. int x, a;
  103. srand(time(NULL));
  104. a=rand()%(1-27);
  105. switch(a){
  106.  
  107. case 1:
  108. x=2;
  109. return x;
  110. break;
  111. case 2:
  112. x=3;
  113. return x;
  114. break;
  115. case 3:
  116. x=5;
  117. return x;
  118. break;
  119. case 4:
  120. x=7;
  121. return x;
  122. break;
  123. case 5:
  124. x=11;
  125. return x;
  126. break;
  127. case 6:
  128. x=13;
  129. return x;
  130. break;
  131. case 7:
  132. x=17;
  133. return x;
  134. break;
  135. case 8:
  136. x=19;
  137. return x;
  138. break;
  139. case 9:
  140. x=23;
  141. return x;
  142. break;
  143. case 10:
  144. x=29;
  145. return x;
  146. break;
  147. case 11:
  148. x=31;
  149. return x;
  150. break;
  151. case 12:
  152. x=37;
  153. return x;
  154. break;
  155. case 13:
  156. x=41;
  157. return x;
  158. break;
  159. case 14:
  160. x=43;
  161. return x;
  162. case 15:
  163. x=47;
  164. return x;
  165. break;
  166. case 16:
  167. x=53;
  168. return x;
  169. break;
  170. case 17:
  171. x=59;
  172. return x;
  173. break;
  174. case 18:
  175. x=61;
  176. return x;
  177. break;
  178. case 19:
  179. x=67;
  180. return x;
  181. break;
  182. case 20:
  183. x=67;
  184. return x;
  185. break;
  186. case 21:
  187. x=71;
  188. return x;
  189. break;
  190. case 22:
  191. x=73;
  192. return x;
  193. break;
  194. case 23:
  195. x=79;
  196. return x;
  197. break;
  198. case 24:
  199. x=83;
  200. return x;
  201. break;
  202. case 25:
  203. x=89;
  204. return x;
  205. break;
  206. case 26:
  207. x=97;
  208. return x;
  209. break;
  210. }
  211.  
  212. return 0;
  213. }
  214.  
  215. void imprimir(int *x, int a){
  216. int i;
  217. for(i=1;i<=a;i++){
  218. printf("\nVector[%i]=%i\n",i, x[i]);
  219. }
  220.  
  221. }
  222. void menu(){
  223. printf("\t MENÚ \n");
  224. printf("1.- SUMA.\n");
  225. printf("2.- RESTA\n");
  226. printf("3.- MULTIPLICACIÓN.\n");
  227. printf("4.- Imprimir tus matrices.\n");
  228. }
  229. void suma(int *x, int *y, int a){
  230. int q;
  231. for(q=0; q<=a;q++){
  232. r[q]=*x++ + *y++;
  233. }
  234.  
  235. }
  236. void resta(int *x, int *y, int a){
  237. int q;
  238. for (q=0;q<=a;q++){
  239. h[q]=*x++ - *y++;
  240. }
  241.  
  242. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement