Advertisement
Guest User

APS1

a guest
Aug 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. typedef struct{
  5.  
  6. int gramas;
  7. float bits;
  8. float price;
  9.  
  10. }Mercado;
  11.  
  12. main()
  13. {
  14. int sup, c, index;
  15.  
  16. printf("Digite o numero de supermercados proximos a Maria\n");
  17. scanf("%i", &sup);
  18. fflush(stdin);
  19.  
  20. Mercado mercados[sup];
  21.  
  22. for(c = 0; c < sup; c++){
  23. scanf("%f %i", &mercados[c].bits, &mercados[c].gramas);
  24. fflush(stdin);
  25. mercados[c].price = 1000 * mercados[c].bits / mercados[c].gramas;
  26. };
  27.  
  28. for(c = 0; c < sup; c++){
  29.  
  30. if(c == 0){
  31.  
  32. index = c;
  33.  
  34. }else{
  35.  
  36. if(mercados[c].price < mercados[index].price){
  37.  
  38. index = c;
  39.  
  40. };
  41.  
  42. };
  43.  
  44. };
  45.  
  46. printf("%.2f", mercados[index].price);
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement