Advertisement
gabriellserra

Trabalho 1

Sep 25th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.30 KB | None | 0 0
  1. #include <stdio.h>
  2. 2 #include <stdlib.h> //biblioteca para "system ("clear")"
  3. 3 #define SIZE_MATRIZ 25 //tamanho maximo de todas as matrizes
  4. 4 #define SIZE_VETOR 20 //tamanho maximo de todos os vetores a exce ssao dos vetores que serao intercalados
  5. 5 #define SIZE_VETOR_2 8 //tamanho dos dois vetores que sao intercal ados
  6. 6 #define SIZE_VETOR_3 16 //tamanho do Vetor Intercalado
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11 // CODIGO DE UMA CALCULADO RA DE VETORES E MATRIZES
  12. 12
  13. 13
  14. 14 //FUNCOES QUE ZERAM A MATRIZ
  15. 15
  16. 16 float zeraMatriz (int tamanhoColunasPrimeiraMatriz, int tamanhoLinhasP rimeiraMatriz, int tamanhoLinhasSegundaMatriz, int tamanhoColunasSegun daMatriz)
  17. 17 {
  18. 18 float resultadoMultiplicacao [SIZE_MATRIZ][SIZE_MATRIZ];
  19. 19 float resultadoTransposta [SIZE_MATRIZ][SIZE_MATRIZ];
  20. 20 float resultadoVetorIntercalado [SIZE_VETOR];
  21. 21 int indiceResultadoVetorIntercalado;
  22. 22 int indiceColunas;
  23. 23 int indiceLinhas;
  24. 24 int indiceGeral;
  25. 25
  26. 26 for (indiceColunas = 0; indiceColunas < tamanhoColunasPrimeiraMatriz ; indiceColunas++)
  27. 27 {
  28. 28 for (indiceLinhas = 0; indiceLinhas < tamanhoLinhasPrimeiraMatriz; indiceLinhas++)
  29. 29 {
  30. 30 resultadoMultiplicacao[indiceLinhas][indiceColunas] = 0;
  31. 31 }
  32. 32 }
  33. 33
  34. 34 for (indiceColunas = 0; indiceColunas < tamanhoColunasSegundaMatriz; indiceColunas++)
  35. 35 {
  36. 36 for (indiceLinhas = 0; indiceLinhas < tamanhoLinhasSegundaMatriz; indiceLinhas++)
  37. 37 {
  38. 38 resultadoTransposta[indiceLinhas][indiceColunas] = 0;
  39. 39 }
  40. 40 }
  41. 41
  42. 42 return 0;
  43. 43 }
  44. 44
  45. 45 //FUNCOES QUE PREENCHEM TANTO VETOR QUANTO MATRIZ
  46. 46
  47. 47 float preenchePrimeiroVetor (float primeiroVetor [SIZE_VETOR], int tam anhoPrimeiroVetor)
  48. 48 {
  49. 49 int indiceGeral;
  50. 50
  51. 51 for (indiceGeral = 0; indiceGeral < tamanhoPrimeiroVetor; indiceGera l++)
  52. 52 {
  53. 53 printf ("Diga os valores para completar o Primeiro Vetor:\n");
  54. 54 scanf ("%f",&primeiroVetor[indiceGeral]);
  55. 55 }
  56. 56
  57. 57 return 0;
  58. 58 }
  59. 59
  60. 60 float preencheSegundoVetor (float segundoVetor [SIZE_VETOR], int taman hoSegundoVetor)
  61. 61 {
  62. 62 int indiceGeral;
  63. 63
  64. 64 for (indiceGeral = 0; indiceGeral < tamanhoSegundoVetor; indiceGeral ++)
  65. 65 {
  66. 66 printf ("Diga os valores para completar o Segundo Vetor:\n");
  67. 67 scanf ("%f",&segundoVetor[indiceGeral]);
  68. 68 }
  69. 69
  70. 70 return 0;
  71. 71 }
  72. 72
  73. 73 float preenchePrimeiroVetorIntercalado (float primeiroVetorIntercalado [SIZE_VETOR], int tamanhoPrimeiroVetorIntercalado)
  74. 74 {
  75. 75 int indiceGeral;
  76. 76
  77. 77 do
  78. 78 {
  79. 79 for (indiceGeral = 0; indiceGeral < 8; indiceGeral++)
  80. 80 {
  81. 81 printf ("Diga os valores para completar o Primeiro Vetor que ser a Intercalado:\n");
  82. 82 scanf ("%f",&primeiroVetorIntercalado[indiceGeral]);
  83. 83 }
  84. 84 }while (indiceGeral != 8);
  85. 85
  86. 86 return 0;
  87. 87 }
  88. 88
  89. 89 float preencheSegundoVetorIntercalado (float segundoVetorIntercalado [ SIZE_VETOR], int tamanhoSegundoVetorIntercalado)
  90. 90 {
  91. 91 int indiceGeral;
  92. 92
  93. 93 do
  94. 94 {
  95. 95 for (indiceGeral = 0; indiceGeral < 8; indiceGeral++)
  96. 96 {
  97. 97 printf ("Diga os valores para completar o Segundo Vetor que sera Ordenado:\n");
  98. 98 scanf ("%f",&segundoVetorIntercalado[indiceGeral]);
  99. 99 }
  100. 100 } while (indiceGeral != 8);
  101. 101
  102. 102 return 0;
  103. 103 }
  104.  
  105. 105 float preenchePrimeiraMatriz (float primeiraMatriz [SIZE_MATRIZ][SIZE_ MATRIZ],int tamanhoColunasPrimeiraMatriz, int tamanhoLinhasPrimeiraMat riz)
  106. 106 {
  107. 107 int indiceColunas;
  108. 108 int indiceLinhas;
  109. 109
  110. 110 for (indiceColunas = 0; indiceColunas < tamanhoColunasPrimeiraMatriz ; indiceColunas++)
  111. 111 {
  112. 112 for (indiceLinhas = 0; indiceLinhas < tamanhoLinhasPrimeiraMatriz; indiceLinhas++)
  113. 113 {
  114. 114 printf ("Diga o valor para completar a %d Linha e %d Coluna da s ua Primeira Matriz:\n", indiceColunas+1, indiceLinhas+1);
  115. 115 scanf ("%f",&primeiraMatriz[indiceLinhas][indiceColunas]);
  116. 116 }
  117. 117 }
  118. 118
  119. 119 return 0;
  120. 120
  121. 121 }
  122. 122
  123. 123 float preencheSegundaMatriz (float segundaMatriz [SIZE_MATRIZ][SIZE_MA TRIZ], int tamanhoColunasSegundaMatriz, int tamanhoLinhasSegundaMatriz )
  124. 124 {
  125. 125 int indiceColunas;
  126. 126 int indiceLinhas;
  127. 127
  128. 128 for (indiceColunas = 0; indiceColunas < tamanhoColunasSegundaMatriz; indiceColunas++)
  129. 129 {
  130. 130 for (indiceLinhas = 0; indiceLinhas < tamanhoLinhasSegundaMatriz; indiceLinhas++)
  131. 131 {
  132. 132 printf ("Diga o valor para completar a %d Linha e %d Coluna da s ua Segunda Matriz:\n", indiceLinhas + 1, indiceColunas + 1);
  133. 133 scanf ("%f",&segundaMatriz[indiceLinhas][indiceColunas]);
  134. 134 }
  135. }
  136. 136
  137. 137 return 0;
  138. 138
  139. 139 }
  140. 140
  141. 141 //FUNCOES QUE PRINTAM TANTO VETOR QUANTO MATRIZ
  142. 142
  143. 143 float mostraPrimeiroVetor (float primeiroVetor [SIZE_VETOR], int taman hoPrimeiroVetor, int indiceGeral)
  144. 144 {
  145. 145
  146. 146 printf ("\t\t\t\t\nSeu Primeiro Vetor:\n");
  147. 147
  148. 148 for (indiceGeral = 0; indiceGeral < tamanhoPrimeiroVetor; indiceGera l++)
  149. 149 {
  150. 150 printf ("[%.5f]\n",primeiroVetor[indiceGeral]);
  151. 151 }
  152. 152
  153. 153 return 0;
  154. 154
  155. 155 }
  156. 156
  157. 157
  158. 158 float mostraSegundoVetor (float segundoVetor [SIZE_VETOR], int tamanho SegundoVetor, int indiceGeral)
  159. 159 {
  160. 160
  161. 161
  162. 162 printf ("\t\t\t\t\nSeu Segundo Vetor:\n");
  163. 163
  164. 164 for (indiceGeral = 0; indiceGeral < tamanhoSegundoVetor; indiceGeral ++)
  165. 165 {
  166. 166 printf ("[%.5f]\n",segundoVetor[indiceGeral]);
  167. 167 }
  168. 168
  169. 169 return 0;
  170. 170
  171. }
  172. 172
  173. 173 float mostraPrimeiraMatriz (float primeiraMatriz [SIZE_MATRIZ][SIZE_MA TRIZ], int tamanhoColunasPrimeiraMatriz, int tamanhoLinhasPrimeiraMatr iz)
  174. 174 {
  175. 175 int indiceColunas;
  176. 176 int indiceLinhas;
  177. 177
  178. 178 for (indiceColunas = 0; indiceColunas < tamanhoColunasPrimeiraMatriz ; indiceColunas++)
  179. 179 {
  180. 180 for (indiceLinhas = 0; indiceLinhas < tamanhoLinhasPrimeiraMatriz; indiceLinhas++)
  181. 181 {
  182. 182 printf ("\t%.5f",primeiraMatriz[indiceLinhas][indiceColunas]);
  183. 183 }
  184. 184 printf ("\n");
  185. 185 }
  186. 186
  187. 187 return 0;
  188. 188 }
  189. 189
  190. 190 float mostraSegundaMatriz (float segundaMatriz [SIZE_MATRIZ][SIZE_MATR IZ], int tamanhoColunasSegundaMatriz, int tamanhoLinhasSegundaMatriz)
  191. 191 {
  192. 192 int indiceColunas;
  193. 193 int indiceLinhas;
  194. 194
  195. 195 for (indiceColunas = 0; indiceColunas < tamanhoColunasSegundaMatriz; indiceColunas++)
  196. 196 {
  197. 197 for (indiceLinhas = 0; indiceLinhas < tamanhoLinhasSegundaMatriz; indiceLinhas++)
  198. 198 {
  199. 199 printf ("\t%.5f",segundaMatriz[indiceLinhas][indiceColunas]);
  200. 200 }
  201. 201 printf ("\n");
  202. 202 }
  203. 203
  204. 204 return 0;
  205. }
  206. 206
  207. 207 float mostraPrimeiroVetorIntercalado (float primeiroVetorIntercalado [ SIZE_VETOR], int tamanhoPrimeiroVetorIntercalado, int indiceGeral)
  208. 208 {
  209. 209
  210. 210 printf ("\t\t\t\t\nSeu Primeiro Vetor a ser Intercalado:\n");
  211. 211
  212. 212 for (indiceGeral = 0; indiceGeral < 8; indiceGeral++)
  213. 213 {
  214. 214 printf ("[%.5f]\n",primeiroVetorIntercalado[indiceGeral]);
  215. 215 }
  216. 216
  217. 217 return 0;
  218. 218 }
  219. 219
  220. 220 float mostraSegundoVetorIntercalado (float segundoVetorIntercalado [SI ZE_VETOR], int tamanhoSegundoVetorIntercalado, int indiceGeral)
  221. 221 {
  222. 222
  223. 223 printf ("\t\t\t\t\nSeu Segundo Vetor a ser Intercalado:\n");
  224. 224
  225. 225 for (indiceGeral = 0; indiceGeral < 8; indiceGeral++)
  226. 226 {
  227. 227 printf ("[%.5f]\n",segundoVetorIntercalado[indiceGeral]);
  228. 228 }
  229. 229
  230. 230 return 0;
  231. 231 }
  232. 232 //FUNCOES DE OPERACOES DO MENU
  233. 233
  234. 234 /* case 1 do Menu de Operacoes */ float somaDoisVetores (float primeir oVetor [SIZE_VETOR], float segundoVetor [SIZE_VETOR], int tamanhoPrime iroVetor, int tamanhoSegundoVetor, float resultadoSoma [SIZE_VETOR])
  235. 235 {
  236. 236 int indiceGeral;
  237. 237
  238. 238 if (tamanhoPrimeiroVetor != tamanhoSegundoVetor)
  239. 239 printf ("Para realizar a soma, os tamanhos devem ser iguais\n");
  240. 240 else
  241. for (indiceGeral = 0; indiceGeral < tamanhoPrimeiroVetor; indice Geral++)
  242. 242 {
  243. 243 resultadoSoma[indiceGeral] = primeiroVetor[indiceGeral] + segu ndoVetor[indiceGeral];
  244. 244 }
  245. 245
  246. 246 printf ("Resultado da soma dos dois Vetores:\n");
  247. 247 for (indiceGeral = 0; indiceGeral < tamanhoPrimeiroVetor; indice Geral++)
  248. 248 {
  249. 249 printf ("[%.5f]\n",resultadoSoma[indiceGeral]);
  250. 250 }
  251. 251
  252. 252
  253. 253 return 0;
  254. 254 }
  255. 255
  256. 256
  257. 257 /* case 4 do Menu de Operacoes */ int ordenaVetorInteiros (int terceir oVetor [SIZE_VETOR], int tamanhoTerceiroVetor)
  258. 258 {
  259. 259 int indice1TerceiroVetor;
  260. 260 int indice2TerceiroVetor;
  261. 261 int auxiliarOrdenacao;
  262. 262
  263. 263 for (indice1TerceiroVetor = 0; indice1TerceiroVetor < tamanhoTerceir oVetor; indice1TerceiroVetor++)
  264. 264 {
  265. 265 for (indice2TerceiroVetor = 0; indice2TerceiroVetor < tamanhoTerce iroVetor; indice2TerceiroVetor++)
  266. 266 {
  267. 267 if (terceiroVetor[indice1TerceiroVetor] < terceiroVetor[indice2T erceiroVetor])
  268. 268 {
  269. 269 auxiliarOrdenacao = terceiroVetor[indice1TerceiroVetor];
  270. 270 terceiroVetor[indice1TerceiroVetor] = terceiroVetor[indice2Ter ceiroVetor];
  271. 271 terceiroVetor[indice2TerceiroVetor] = auxiliarOrdenacao;
  272. 272 }
  273. 273 }
  274. }
  275. 275
  276. 276 for (indice1TerceiroVetor = 0; indice1TerceiroVetor < tamanhoTerceir oVetor; indice1TerceiroVetor++)
  277. 277 {
  278. 278 printf ("[%d]\n", terceiroVetor[indice1TerceiroVetor]);
  279. 279 }
  280. 280
  281. 281 return 0;
  282. 282 }
  283. 283
  284. 284 /* case 6 do Menu de Operacoes*/ float multiplicacaoMatrizes (float p rimeiraMatriz[SIZE_MATRIZ][SIZE_MATRIZ], float segundaMatriz[SIZE_MATR IZ][SIZE_MATRIZ], int tamanhoColunasPrimeiraMatriz, int tamanhoLinhasP rimeiraMatriz, int tamanhoColunasSegundaMatriz, int tamanhoLinhasSegun daMatriz)
  285. 285 {
  286. 286
  287. 287 float resultadoMultiplicacao[SIZE_MATRIZ][SIZE_MATRIZ];
  288. 288 int auxiliarMultiplicacao;
  289. 289 int indiceColunasGeral;
  290. 290 int indiceLinhasGeral;
  291. 291 int indiceColunas;
  292. 292 int indiceLinhas;
  293. 293 int indiceGeral;
  294. 294
  295. 295 for (indiceColunas = 0; indiceColunas < tamanhoColunasPrimeiraMatriz ; indiceColunas++)
  296. 296 {
  297. 297 for (indiceLinhas = 0; indiceLinhas < tamanhoLinhasPrimeiraMatriz; indiceLinhas++)
  298. 298 {
  299. 299 resultadoMultiplicacao[indiceLinhas][indiceColunas] = (primeiraM atriz[indiceLinhas][indiceColunas] * segundaMatriz[indiceLinhas][indic eColunas]);
  300. 300 }
  301. 301 }
  302. 302
  303. 303 for (indiceColunas = 0; indiceColunas < tamanhoColunasPrimeiraMatriz ; indiceColunas++)
  304. 304 {
  305. or (indiceLinhas = 0; indiceLinhas < tamanhoLinhasPrimeiraMatriz; indiceLinhas++)
  306. 306 {
  307. 307 printf ("\t%.5f",resultadoMultiplicacao[indiceLinhas][indiceColu nas]);
  308. 308 }
  309. 309 printf ("\n");
  310. 310 }
  311. 311
  312. 312 return 0;
  313. 313 }
  314. 314
  315. 315 float mediaVetor (float primeiroVetor [SIZE_VETOR], float segundoVetor [SIZE_VETOR], float vetorMedia [SIZE_VETOR], int tamanhoPrimeiroVetor , int mediaTotalVetor)
  316. 316 {
  317. 317
  318. 318 int indice;
  319. 319
  320. 320 /* for (indice = 0; indice < tamanhoPrimeiroVetor; indice++)
  321. 321 {
  322. 322 vetorMedia[indice] = primeiroVetor[indice]/segundoVetor[indice];
  323. 323 }
  324. 324
  325. 325 for (indice = 0; indice < tamanhoPrimeiroVetor; indice++)
  326. 326 {
  327. 327 printf ("Media dos dois vetores:\n [%f]\n",vetorMedia[indice]);
  328. 328 }
  329. 329 */
  330. 330
  331. 331 for (indice = 0; indice < tamanhoPrimeiroVetor; indice++)
  332. 332 {
  333. 333 mediaTotalVetor = (mediaTotalVetor + primeiroVetor[indice])/tamanh oPrimeiroVetor;
  334. 334 }
  335. 335
  336. 336 printf ("%d",mediaTotalVetor);
  337. 337
  338. 338 return 0;
  339. 339
  340. }
  341. 341
  342. 342
  343. 343
  344. 344
  345. 345 //FUNCAO PRINCIPAL
  346. 346
  347. 347 int main ()
  348. 348 {
  349. 349
  350. 350 // variaveis de vetores e matrizes
  351. 351 float resultadoMultiplicacao[SIZE_MATRIZ][SIZE_MATRIZ];
  352. 352 float resultadoTransposta[SIZE_MATRIZ][SIZE_MATRIZ];
  353. 353 float segundaMatriz[SIZE_MATRIZ][SIZE_MATRIZ];
  354. 354 float primeiraMatriz[SIZE_MATRIZ][SIZE_MATRIZ];
  355. 355 float primeiroVetorIntercalado [SIZE_VETOR_2];
  356. 356 float resultadoVetorIntercalado[SIZE_VETOR_3];
  357. 357 float segundoVetorIntercalado [SIZE_VETOR_2];
  358. 358 int resultadoProduto[SIZE_VETOR];
  359. 359 float resultadoSoma [SIZE_VETOR];
  360. 360 float primeiroVetor[SIZE_VETOR];
  361. 361 int terceiroVetor[SIZE_VETOR];
  362. 362 float segundoVetor[SIZE_VETOR];
  363. 363 float vetorMedia [SIZE_VETOR];
  364. 364 float mediaTotalVetor = 0;
  365. 365 // variaveis de tamanho e indice dos Vetores e Matrizes
  366. 366 int tamanhoPrimeiroVetorIntercalado;
  367. 367 int indiceResultadoVetorIntercalado;
  368. 368 int tamanhoSegundoVetorIntercalado;
  369. 369 int tamanhoColunasPrimeiraMatriz;
  370. 370 int tamanhoLinhasPrimeiraMatriz;
  371. 371 int tamanhoColunasSegundaMatriz;
  372. 372 int tamanhoLinhasSegundaMatriz;
  373. 373 int tamanhoPrimeiroVetor;
  374. 374 int indice1TerceiroVetor;
  375. 375 int indice2TerceiroVetor;
  376. 376 int tamanhoTerceiroVetor;
  377. 377 int tamanhoSegundoVetor;
  378. 378 int indiceResultado;
  379. 379 int indiceColunas;
  380. int indiceLinhas;
  381. 381 int indiceGeral;
  382. 382
  383. 383 // outras variaveis
  384. 384 int resultadoFinalProduto;
  385. 385 int auxiliarMultiplicacao;
  386. 386 int auxiliarIntercalado2;
  387. 387 int auxiliarIntercalado;
  388. 388 int auxiliarPrintaFinal;
  389. 389 int auxiliarSaida;
  390. 390 int auxiliarSaida2;
  391. 391 int auxiliarOrdenacao;
  392. 392 char auxiliarExclusao;
  393. 393 int myBoolean2;
  394. 394 int myBoolean3;
  395. 395 int myBoolean;
  396. 396 int preOpcoes;
  397. 397 int opcoes;
  398. 398
  399. 399 // printf ("\n\tAntes de comecar, e necessario definir o tamanho dos vetores e matrizes que serao trabalhadas\n\n");
  400. 400 printf ("\n Calculadora de Matrizes e Vetores\n\n");
  401. 401
  402. 402 while (myBoolean == 0)
  403. 403 {
  404. 404 do
  405. 405 {
  406. 406 printf (" Menu Principal\n");
  407. 407 printf (" | (1)Definir tamanho e parametros do primeiro vetor |\n");
  408. 408 printf (" | (2)Definir tamanho e parametros do segundo vetor |\n");
  409. 409 printf (" | (3)Definir tamanho e parametros da primeira matriz |\n");
  410. 410 printf (" | (4)Definir tamanho e parametros da segunda matriz |\n");
  411. 411 printf (" | (5)Sair para o Menu de Operacoes |\n");
  412. 412 scanf ("%d",&preOpcoes);
  413. 413 system ("clear");
  414. 414 } while ((preOpcoes < 1) || (preOpcoes > 5));
  415. 415
  416. 416 switch (preOpcoes)
  417. 417 {
  418. 418 case 1:
  419. 419 {
  420. 420 printf ("\nQual o tamanho do seu Primeiro Vetor? Respostas negativas ou maiores que 20 nao serao consideradas:\n");
  421. scanf ("%d",&tamanhoPrimeiroVetor);
  422. 422
  423. 423 if (tamanhoPrimeiroVetor > 0)
  424. 424 auxiliarPrintaFinal = 0;
  425. 425 else
  426. 426 auxiliarPrintaFinal = 1;
  427. 427 } while ((tamanhoPrimeiroVetor < 0) || (tamanhoPrimeiroVetor > 20));
  428. 428
  429. 429
  430. 430 /*F*/ preenchePrimeiroVetor (primeiroVetor, tamanhoPrimeiroVetor);
  431. 431 /*F*/ mostraPrimeiroVetor (primeiroVetor, tamanhoPrimeiroVetor, indiceGeral);
  432. 432
  433. 433 printf ("\nAperte 'x' para apagar o seu Primeiro Vetor\n");
  434. 434 scanf ("%c",&auxiliarExclusao);
  435. 435
  436. 436 do
  437. 437 {
  438. 438 if (auxiliarExclusao == 'x')
  439. 439 {
  440. 440 for (indiceGeral = 0; indiceGeral < tamanhoPrimeiroVetor; indiceGeral++)
  441. 441 {
  442. 442 primeiroVetor[indiceGeral] = 0;
  443. 443 }
  444. 444
  445. 445 system ("clear");
  446. 446 printf ("Seu Primeiro Vetor foi excluido da calculadora, para inserir um novo Vetor volte ao Menu Principal apertando 0\n");
  447. 447 }
  448. 448 else
  449. 449 printf ("Aperte 0 para voltar ao Menu Principal\n");
  450. 450 scanf ("%d",&auxiliarSaida);
  451. 451 system ("clear");
  452. 452
  453. 453 } while (auxiliarSaida != 0 && auxiliarExclusao != 'x' && myBoolean != 0);
  454. 454
  455. 455 if (auxiliarSaida == 0)
  456. 456 {
  457. 457 myBoolean = 0;
  458. 458 }
  459. 459 else;
  460. 460 break;
  461. 461
  462. 462 while (myBoolean == 1)
  463. case 2:
  464. 464 do
  465. 465 {
  466. 466 printf ("\nQual o tamanho do seu Segundo Vetor? Respostas negativas ou maiores que 20 nao serao consideradas:\n");
  467. 467 scanf ("%d",&tamanhoSegundoVetor);
  468. 468 } while ((tamanhoSegundoVetor < 0) || (tamanhoSegundoVetor > 20));
  469. 469
  470. 470 if (tamanhoPrimeiroVetor > 0)
  471. 471 auxiliarPrintaFinal = 0;
  472. 472 else
  473. 473 auxiliarPrintaFinal = 1;
  474. 474
  475. 475 /*F*/ preencheSegundoVetor (segundoVetor, tamanhoSegundoVetor);
  476. 476 /*F*/ mostraSegundoVetor (segundoVetor, tamanhoSegundoVetor, indiceGeral);
  477. 477
  478. 478 printf ("\nAperte 'x' para apagar o seu Segundo Vetor\n");
  479. 479 scanf ("%c",&auxiliarExclusao);
  480. 480
  481. 481 do
  482. 482 {
  483. 483 if (auxiliarExclusao == 'x')
  484. 484 {
  485. 485 for (indiceGeral = 0; indiceGeral < tamanhoSegundoVetor; indiceGeral++)
  486. 486 {
  487. 487 segundoVetor[indiceGeral] = 0;
  488. 488 }
  489. 489
  490. 490 system ("clear");
  491. 491 printf ("Seu Segundo Vetor foi excluido da calculadora, para inserir um novo Vetor volte ao Menu Principal apertando 0\n");
  492. 492 }
  493. 493 else
  494. 494 printf ("Aperte 0 para voltar ao Menu Principal\n");
  495. 495 scanf ("%d",&auxiliarSaida);
  496. 496 system ("clear");
  497. 497
  498. 498 } while (auxiliarSaida != 0 && auxiliarExclusao != 'x');
  499. 499
  500. 500 if (auxiliarSaida == 0)
  501. 501 {
  502. 502 myBoolean = 0;
  503. 503 }
  504. 504 else;
  505. break;
  506. 506
  507. 507 case 3:
  508. 508 do
  509. 509 {
  510. 510 printf ("\nQuantas linhas tem a sua Primeira Matriz? Respostas negativas ou maiores que 20 nao serao consideradas:\n");
  511. 511 scanf ("%d",&tamanhoLinhasPrimeiraMatriz);
  512. 512
  513. 513 printf ("\nQuantas colunas tem a sua Primeira Matriz? Respostas negativas ou maiores que 20 nao serao consideradas:\n");
  514. 514 scanf ("%d",&tamanhoColunasPrimeiraMatriz);
  515. 515 } while ((tamanhoColunasPrimeiraMatriz < 0) || (tamanhoColunasPrimeiraMatriz > 20));
  516. 516
  517. 517 /*F*/ preenchePrimeiraMatriz (primeiraMatriz, tamanhoColunasPrimeiraMatriz, tamanhoLinhasPrimeiraMatriz);
  518. 518 /*F*/ mostraPrimeiraMatriz (primeiraMatriz, tamanhoColunasPrimeiraMatriz, tamanhoLinhasPrimeiraMatriz);
  519. 519
  520. 520 printf ("\nAperte 'x' para apagar o sua Primeira Matriz\n");
  521. 521 scanf ("%c",&auxiliarExclusao);
  522. 522
  523. 523 do
  524. 524 {
  525. 525 if (auxiliarExclusao == 'x')
  526. 526 {
  527. 527 for (indiceColunas = 0; indiceColunas < tamanhoColunasPrimeiraMatriz; indiceColunas++)
  528. 528 {
  529. 529 for (indiceLinhas = 0; indiceLinhas < tamanhoLinhasPrimeiraMatriz; indiceLinhas++)
  530. 530 {
  531. 531 primeiraMatriz[indiceLinhas][indiceColunas] = 0;
  532. 532 }
  533. 533 }
  534. 534
  535. 535 system ("clear");
  536. 536 printf ("Sua Primeira Matriz foi excluida da calculadora, para inserir uma nova Matriz volte ao Menu Principal apertando 0\n");
  537. 537 }
  538. 538 else
  539. 539 printf ("Aperte 0 para voltar ao menu principal\n");
  540. 540 scanf ("%d",&auxiliarSaida);
  541. 541 system ("clear");
  542. 542
  543. 543 } while (auxiliarSaida != 0 && auxiliarExclusao != 'x');
  544. 544
  545. 545 if (auxiliarSaida == 0)
  546. 546 {
  547. myBoolean = 0;
  548. 548 }
  549. 549 else
  550. 550 myBoolean = 1;
  551. 551 break;
  552. 552
  553. 553 case 4:
  554. 554 do
  555. 555 {
  556. 556 printf ("\nQuantas linhas tem a sua Segunda Matriz? Respostas negativas ou maiores que 20 nao serao consideradas:\n");
  557. 557 scanf ("%d",&tamanhoLinhasSegundaMatriz);
  558. 558
  559. 559 printf ("\nQuantas colunas tem a sua Segunda Matriz? Respostas negativas ou maiores que 20 nao serao consideradas:\n");
  560. 560 scanf ("%d",&tamanhoColunasSegundaMatriz);
  561. 561 } while ((tamanhoColunasSegundaMatriz < 0) || (tamanhoColunasSegundaMatriz > 20));
  562. 562
  563. 563 /*F*/ preencheSegundaMatriz (segundaMatriz, tamanhoColunasSegundaMatriz, tamanhoLinhasSegundaMatriz);
  564. 564 /*F*/ mostraSegundaMatriz (segundaMatriz, tamanhoColunasSegundaMatriz, tamanhoLinhasSegundaMatriz);
  565. 565
  566. 566 printf ("\nAperte 'x' para excluir sua Segunda Matriz\n");
  567. 567 scanf ("%c",&auxiliarExclusao);
  568. 568
  569. 569 do
  570. 570 {
  571. 571 if (auxiliarExclusao == 'x')
  572. 572 {
  573. 573 for (indiceColunas = 0; indiceColunas < tamanhoColunasPrimeiraMatriz; indiceColunas++)
  574. 574 {
  575. 575 for (indiceLinhas = 0; indiceLinhas < tamanhoLinhasPrimeiraMatriz; indiceLinhas++)
  576. 576 {
  577. 577 primeiraMatriz[indiceLinhas][indiceColunas] = 0;
  578. 578 }
  579. 579 }
  580. 580
  581. 581 system ("clear");
  582. 582 printf ("Sua Segunda Matriz foi excluida da calculadora, para inserir uma nova Matriz volte ao Menu Principal apertando 0\n");
  583. 583 }
  584. 584 else
  585. 585 printf ("Aperte 0 para voltar ao menu principal\n");
  586. 586 scanf ("%d",&auxiliarSaida);
  587. 587 system ("clear");
  588. 588
  589. } while (auxiliarSaida != 0 && auxiliarExclusao != 'x');
  590. 590
  591. 591 if (auxiliarSaida == 0)
  592. 592 {
  593. 593 myBoolean = 0;
  594. 594 }
  595. 595
  596. 596 break;
  597. 597
  598. 598 case 5:
  599. 599 myBoolean = 1;
  600. 600 myBoolean2 = 0;
  601. 601 break;
  602. 602 }
  603. 603
  604. 604 while (myBoolean2 == 0 && myBoolean != 0)
  605. 605 {
  606. 606 do
  607. 607 {
  608. 608 printf (" Menu de Operacoes\n\n");
  609. 609 printf (" | (1)Soma de dois vetores |\n");
  610. 610 printf (" | (2)Media de dois vetores |\n");
  611. 611 // printf (" | (2)Produto interno de dois vetores |\n");
  612. 612 // printf (" | (3)Intercala dois vetores de 8 posicoes em um vetor de 16 |\n");
  613. 613 printf (" | (4)Ordenacao de um vetor de inteiros em ordem crescente |\n");
  614. 614 // printf (" | (5)Transposta de uma matriz |\n");
  615. 615 // printf (" | (6)Multiplicacao de duas matrizes |\n");
  616. 616 printf (" | (7)Retornar ao Menu Principal |\n");
  617. 617 printf (" | (8)Sair da Calculadora |\n");
  618. 618
  619. 619 printf ("\nSeu PrimeiroVetor:\n");
  620. 620 for (indiceGeral = 0; indiceGeral < tamanhoPrimeiroVetor; indiceGeral++)
  621. 621 {
  622. 622 printf ("[%.5f]\n",primeiroVetor[indiceGeral]);
  623. 623 }
  624. 624
  625. 625 printf ("\nSeu Segundo Vetor:\n");
  626. 626 for (indiceGeral = 0; indiceGeral < tamanhoPrimeiroVetor; indiceGeral++)
  627. 627 {
  628. 628 printf ("[%.5f]\n",segundoVetor[indiceGeral]);
  629. 629 }
  630. 630
  631. printf ("\nSua Primeira Matriz:\n");
  632. 632 for (indiceColunas = 0; indiceColunas < tamanhoColunasPrimeiraMatriz; indiceColunas++)
  633. 633 {
  634. 634 for (indiceLinhas = 0; indiceLinhas < tamanhoLinhasPrimeiraMatriz; indiceLinhas++)
  635. 635 {
  636. 636 printf ("\t%.5f",primeiraMatriz[indiceLinhas][indiceColunas]);
  637. 637 }
  638. 638 printf ("\n");
  639. 639 }
  640. 640
  641. 641 printf ("\nSua Segunda Matriz:\n");
  642. 642 for (indiceColunas = 0; indiceColunas < tamanhoColunasSegundaMatriz; indiceColunas++)
  643. 643 {
  644. 644 for (indiceLinhas = 0; indiceLinhas < tamanhoLinhasSegundaMatriz; indiceLinhas++)
  645. 645 {
  646. 646 printf ("\t%.5f",segundaMatriz[indiceLinhas][indiceColunas]);
  647. 647 }
  648. 648 printf ("\n");
  649. 649 }
  650. 650
  651. 651 printf ("\nQual operacao voce deseja realizar?\n");
  652. 652 scanf ("%d",&opcoes);
  653. 653 system ("clear");
  654. 654 } while ((opcoes < 1) || (opcoes > 9));
  655. 655
  656. 656 switch (opcoes)
  657. 657 {
  658. 658 case 1:
  659. 659 somaDoisVetores (primeiroVetor, segundoVetor, tamanhoPrimeiroVetor, tamanhoSegundoVetor, resultadoSoma);
  660. 660 do
  661. 661 {
  662. 662 printf ("Aperte 0 para voltar ao menu principal\n");
  663. 663 scanf ("%d",&auxiliarSaida2);
  664. 664 system ("clear");
  665. 665 } while (auxiliarSaida2 != 0);
  666. 666
  667. 667 if (auxiliarSaida2 == 0)
  668. 668 {
  669. 669 myBoolean = 0;
  670. 670 }
  671. 671 else;
  672. 672 break;
  673. 674 case 2:
  674. 675 system ("clear");
  675. 676 mediaVetor (primeiroVetor, segundoVetor, vetorMedia, tamanhoPrimeiroVetor, mediaTotalVetor);
  676. 677 break;
  677. 678
  678. 679
  679. 680
  680. 681 /*case 2:
  681. 682 produtoInternoVetores (primeiroVetor, segundoVetor, tamanhoPrimeiroVetor, tamanhoSegundoVetor);
  682. 683 break;
  683. 684 case 3:
  684. 685 F preenchePrimeiroVetorIntercalado ( primeiroVetorIntercalado, tamanhoPrimeiroVetorIntercalado);
  685. 686 F mostraPrimeiroVetorIntercalado ( primeiroVetorIntercalado, tamanhoPrimeiroVetorIntercalado, indiceGeral);
  686. 687
  687. 688 F preencheSegundoVetorIntercalado ( segundoVetorIntercalado, tamanhoSegundoVetorIntercalado);
  688. 689 F mostraSegundoVetorIntercalado ( segundoVetorIntercalado, tamanhoSegundoVetorIntercalado, indiceGeral);
  689. 690
  690. 691 F intercalaDoisVetores (primeiroVetorIntercalado , segundoVetorIntercalado , tamanhoPrimeiroVetorIntercalado, tamanhoSegundoVetorIntercalado, in diceGeral);
  691. 692 do
  692. 693 {
  693. 694 printf ("Aperte 0 para voltar ao menu principal\n");
  694. 695 scanf ("%d",&auxiliarSaida2);
  695. 696 system ("clear");
  696. 697 } while (auxiliarSaida2 != 0);
  697. 698
  698. 699 break;*/
  699. 700
  700. 701 case 4:
  701. 702 printf ("Qual o tamanho do vetor que voce deseja ordenar?\n");
  702. 703 scanf ("%d",&tamanhoTerceiroVetor);
  703. 704
  704. 705 for (indice1TerceiroVetor = 0; indice1TerceiroVetor < tamanhoTerceiroVetor; indice1TerceiroVetor++)
  705. 706 {
  706. 707 printf ("Diga os valores para preencher o seu vetor:\n");
  707. 708 scanf ("%d",&terceiroVetor[indice1TerceiroVetor]);
  708. 709 }
  709. 710
  710. 711 /*F*/ ordenaVetorInteiros (terceiroVetor, tamanhoTerceiroVetor);
  711. 712
  712. 713 do
  713. {
  714. 715 printf ("Aperte 0 para voltar ao menu principal\n");
  715. 716 scanf ("%d",&auxiliarSaida2);
  716. 717 system ("clear");
  717. 718 } while (auxiliarSaida2 != 0);
  718. 719
  719. 720 break;
  720. 721
  721. 722 /*case 5:
  722. 723 if (tamanhoColunasPrimeiraMatriz <= 0 && tamanhoLinhasPrimeiraMatriz <= 0 && tamanhoColunasSegundaMatriz <= 0 && tamanhoLinhasSegundaMatri z <= 0)
  723. 724 printf ("ERRO: Para realizar a Operacao 5 e necessario definir os parametros da sua Matriz\n\n");
  724. 725 else
  725. 726 F zeraMatriz (tamanhoColunasPrimeiraMatriz, tamanhoLinhasPrimeiraMatriz, tamanhoColunasSegundaMatriz, tamanhoLinhasSegundaMatriz);
  726. 727 F transpostaMatriz (primeiraMatriz, segundaMatriz, tamanhoColunasPrimeiraMatriz, tamanhoLinhasPrimeiraMatriz, tamanhoColunasSegundaMatriz, t amanhoLinhasSegundaMatriz);
  727. 728
  728. 729 do
  729. 730 {
  730. 731 printf ("Aperte 0 para voltar ao menu principal\n");
  731. 732 scanf ("%d",&auxiliarSaida2);
  732. 733 system ("clear");
  733. 734 } while (auxiliarSaida2 != 0);
  734. 735 break;*/
  735. 736
  736. 737 case 6:
  737. 738 if (tamanhoColunasPrimeiraMatriz <= 0 && tamanhoLinhasPrimeiraMatriz <= 0 && tamanhoColunasSegundaMatriz <= 0 && tamanhoLinhasSegundaMatri z <= 0)
  738. 739 printf ("ERRO: Para realizar a Operacao 6 e necessario definir os parametros da sua Matriz\n\n");
  739. 740 else
  740. 741 /*F*/ zeraMatriz (tamanhoColunasPrimeiraMatriz, tamanhoLinhasPrimeiraMatriz, tamanhoColunasSegundaMatriz, tamanhoLinhasSegundaMatriz);
  741. 742 /*F*/ multiplicacaoMatrizes (primeiraMatriz, segundaMatriz, tamanhoColunasPrimeiraMatriz, tamanhoLinhasPrimeiraMatriz, tamanhoColunasSegunda Matriz, tamanhoLinhasSegundaMatriz);
  742. 743
  743. 744 do
  744. 745 {
  745. 746 printf ("Aperte 0 para voltar ao menu principal\n");
  746. 747 scanf ("%d",&auxiliarSaida2);
  747. 748 system ("clear");
  748. 749 } while (auxiliarSaida2 != 0);
  749. 750 break;
  750. 751 case 7:
  751. myBoolean = 0;
  752. 753 myBoolean2 = 1;
  753. 754 break;
  754. 755 case 8:
  755. 756 myBoolean2 = 1;
  756. 757 break;
  757. 758 }
  758. 759 }
  759. 760 }
  760. 761 return 0;
  761. 762 }
  762. 763
  763. 764 /*AUTORIA: GABRIEL SERRA MANHAES
  764. 765 DRE: 116183338
  765. 766 MATERIA: COMPUTACAO 1
  766. 767 */
  767. 768
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement