Advertisement
Five_NT

[C++]Cate muchii au cost maxim si care sunt

Nov 20th, 2013
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. //Sa se afiseze cate muchii au costul maxim si care sunt aceste muchii.
  2. #include<iostream>
  3.  
  4. using namespace std;
  5.  
  6. int a[10][10], i, j, n, k, m, c, v[50], t, x, b[50];
  7.  
  8. void citire ()
  9. {
  10.     cout<<"Nr de varfuri: "; cin>>n;
  11.     cout<<"Nr de muchii: "; cin>>m;
  12.     for(k=1; k<=m; k++)
  13.     {
  14.         cout<<"Varful 1 al muchiei "<<k<<" : ";cin>>i;
  15.         cout<<"Varful 2 al muchiei "<<k<<" : ";cin>>j;
  16.         cout<<"Costul muchiei "<<k<<" : "; cin>>c;
  17.         t++;
  18.         v[t]=c;
  19.     }  
  20. }
  21.  
  22. void cost_maxim ()
  23. {
  24.     int maxi=v[1], nr=0;
  25.     for(t=1; t<=m; t++)
  26.         if(maxi<v[t])
  27.             maxi=v[t];
  28.    
  29.     for(t=1; t<=m; t++)
  30.         if(v[t]==maxi)
  31.         {
  32.             nr++;
  33.             x++;
  34.             b[x]=t;
  35.         }
  36.     cout<<"* "<<nr<<" muchii au costul maxim ("<<maxi<<")"<<'\n';
  37.     cout<<"* "<<"Muchiile care au costul maxim sunt:"<<'\n';
  38.     for(x=1; x<=nr; x++)
  39.         cout<<"** "<<b[x]<<'\n';
  40. }
  41. int main ()
  42. {
  43.     citire();
  44.     cost_maxim();
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement