Advertisement
Guest User

BusquedaE1

a guest
May 20th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <stdio.h>
  2. int CONTROL (int,int);
  3. float MAYOR (float);
  4. void CARGA (int[],float[],int);
  5. int BUSQUEDA (int[],int,int);
  6. main()
  7. {
  8. int cprod[5], codsul, POS;
  9. float pu[5];
  10. CARGA (cprod,pu,5);
  11. printf("\n Ingrese codigo producto a consultar");
  12. scanf("%d",&codsul);
  13. POS=BUSQUEDA(cprod,codsul,10);
  14. if(POS>=0)
  15. { printf("\n Precio %.2f",pu [POS]);
  16. }
  17. else
  18. { printf("\n No existe producto");
  19. }
  20. }
  21. //////////////////////////////////////////////
  22. void CARGA(int VC[],float VP[],int n)
  23. {
  24. int I;
  25. for(I=0;I<n;I++)
  26. {printf("\n Ingrese codigo de producto:");
  27. VC[I]=CONTROL(100,999);
  28. printf("\n Ingrese precio de producto:");
  29. VP[I]=MAYOR(0);
  30. }
  31. }
  32. /////////////////////////////////////////////
  33. int CONTROL (int LI,int LS)
  34. {
  35. int dato;
  36. do
  37. {
  38. printf("\n Ingrese dato:");
  39. scanf("%d",&dato);
  40. }
  41. while(dato<LI || dato>LS);
  42.  
  43. return (dato);
  44. }
  45. ///////////////////////////////////////////////
  46. float MAYOR(float valor)
  47. {
  48. float dato;
  49. do
  50. {
  51. printf("\n Ingrese dato:");
  52. scanf("%f",&dato);
  53.  
  54. }
  55. while(dato<=valor);
  56.  
  57. return(dato);
  58. }
  59. ///////////////////////////////////////////////
  60. int BUSQUEDA (int V[],int dato, int n)
  61. {int I, POSI;
  62. I=0;
  63. POSI=-1;
  64. while((POSI==-1)&&(I<n))
  65. if(V[I]==dato)
  66. POSI=I;
  67. else
  68. I++;
  69. return(POSI);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement