Proiect Informatica Greedy

Proiectul nostru e de nota 10.


You are not connected. Please login or register

Problema bancnotelor

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Problema bancnotelor on Wed Apr 29, 2015 8:21 am

#include<iostream.h>
int B[30],n,i,S;
void Sort(int k, int X[20]){
int inversari,man;
do{
inversari=0;
for(i=1;i<=k-1;i++)
if(X[i]<X[i+1])
{man=X[i];
X[i]=X[i+1];
X[i+1]=man;
inversari=1;}
}while(inversari);
}
main()
{ cout<<"S="; cin>>S;
 cout<<"N="; cin>>n;
for(i=1;i<=n;i++){ cout<<"Bancnote de valoarea";
                  cin>>B[i];}
Sort(n,B);
i=1;
while(S)
{if(S/B[i]){cout<<S/B[i]<<" bancnote de valoarea "<<B[i]<<endl;
S-=S/B[i]*B[i];}
i++;
}
}

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum