Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- using namespace std;
- int a[100];
- int conchange(int coin[],int tc, int v)
- {
- int i, cn = 0;
- for(i = 0; i < tc; i++)
- {
- while(v>=coin[i])
- {
- v -= coin[i];
- a[cn] = coin[i];
- cn++;
- }
- if(v == 0)
- break;
- }
- return cn;
- }
- void sort(int coin[], int tc)
- {
- int key;
- int j=0,n;
- for(int i=1;i<tc;i++){
- key=coin[i];
- j=i-1;
- while(j>=0 && coin[j]<key){
- coin[j+1]=coin[j];
- j=j-1;
- }
- coin[j+1]=key;
- }
- }
- int main()
- {
- int tc;
- cout<<"Total Currency you have: ";
- cin>>tc;
- int coin[tc];
- cout<<"Currency you have: ";
- for(int i=0;i<tc;i++){
- cin>>coin[i];
- }
- sort(coin,tc);
- int n=tc;
- cout<<"Your Friends amount: ";
- int v;
- cin>>v;
- int c = conchange(coin,tc,v);
- cout<<"Amount of coins: "<<c<<endl;
- cout<<"All coins: ";
- for(int i = 0; i < c; i++)cout<<a[i]<<" ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement