Advertisement
gmmmarcos

Estructuras- ejercicio 2

May 28th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. void CargarArregloInt (int [], char [][30]);
  6. int BuscarMatricula (int []);
  7.  
  8.  
  9.  
  10. int main()
  11. {
  12. int matricula[20];
  13. char nombre[20][30];
  14. int posicion=0;
  15.  
  16.  
  17.  
  18. CargarArregloInt(matricula,nombre);
  19. posicion=BuscarMatricula(matricula);
  20.  
  21. printf ("\n la posicion en el arreglo es: %i", posicion);
  22.  
  23.  
  24.  
  25. return 0;
  26. }
  27.  
  28.  
  29. /// Sean los arreglos paralelos:
  30. /// int matricula[20], char nombre[20][30].
  31.  
  32. /// 1.Crear una función que los cargue, hasta que el usuario lo decida.
  33.  
  34. void CargarArregloInt (int x[20],char y[20][30])
  35. {
  36. int i = 0;
  37. char respuesta='s';
  38.  
  39. while (i<20 && respuesta=='s')
  40. {
  41. printf ("\n Ingrese el numero de matricula: \n");
  42. scanf("%i",&x[i]);
  43.  
  44.  
  45. fflush(stdin);
  46. printf ("\n Ingrese el nombre del alumno: \n");
  47. scanf ("%s",&y[i]);
  48.  
  49. i++;
  50. printf ("\n Desea cargar otro numero en el arreglo?\n");
  51. fflush(stdin);
  52. scanf("%c",&respuesta);
  53.  
  54. }
  55. }
  56.  
  57.  
  58. /// 2.Crear una función que busque dentro del arreglo de matrículas y retorne la posición de un determinado valor.
  59.  
  60. int BuscarMatricula (int x[])
  61. {
  62. int i=0;
  63. int buscado=0;
  64. printf ("\n Ingrese la matricula que desea buscar: \n");
  65. scanf("%i",&buscado);
  66.  
  67. while (x[i]!=buscado)
  68. {
  69. i++;
  70. }
  71.  
  72. return i;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement