Advertisement
Five_NT

[C++]Cate muchii au costul mai mare decat costul mediu

Nov 20th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. //Cate muchii au costul sunt mai mare decate costul mediu
  2. #include <iostream>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. int n, a[10][10] ,i ,j ,k, m, c, nr, v[50], t, ma;
  8.  
  9. void citire ()
  10. {
  11.     ifstream f("citire.in");
  12.     f>>n;
  13.     f>>m;
  14.     for(k=1;k<=m;k++)
  15.     {
  16.         f>>i;
  17.         f>>j;
  18.         f>>c;
  19.         t++;
  20.         v[t]=c;
  21.     }  
  22.     f.close();
  23. }
  24.  
  25. void numar()
  26. {
  27.     int s=0;
  28.     for(t=1; t<=m; t++)
  29.         s=s+v[t];
  30.     ma=s/m;
  31.     for(t=1; t<=m; t++)
  32.         if(v[t]>ma) nr++;
  33.     cout<<'\n';
  34.     cout<<nr<<" muchii au costul mai mare decat costul mediu. ("<<ma<<")";
  35.    
  36. }
  37. int main ()
  38. {
  39.     citire();
  40.     numar();
  41.     return 0;
  42. }
  43. /* citire.in */
  44. 5
  45. 7
  46. 1
  47. 2
  48. 1
  49. 1
  50. 3
  51. 2
  52. 1
  53. 4
  54. 3
  55. 2
  56. 3
  57. 4
  58. 2
  59. 5
  60. 5
  61. 4
  62. 3
  63. 6
  64. 3
  65. 5
  66. 7
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement