Advertisement
saykotislam

Untitled

Jul 27th, 2021
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4. int a[100];
  5. int conchange(int coin[],int tc, int v)
  6. {
  7.     int i, cn = 0;
  8.     for(i = 0; i < tc; i++)
  9.     {
  10.         while(v>=coin[i])
  11.         {
  12.             v -= coin[i];
  13.             a[cn] = coin[i];
  14.             cn++;
  15.         }
  16.         if(v == 0)
  17.             break;
  18.     }
  19.     return cn;
  20. }
  21.  
  22. void sort(int coin[], int tc)
  23. {
  24.     int key;
  25.     int j=0,n;
  26.     for(int i=1;i<tc;i++){
  27.         key=coin[i];
  28.         j=i-1;
  29.         while(j>=0 && coin[j]<key){
  30.             coin[j+1]=coin[j];
  31.             j=j-1;
  32.         }
  33.         coin[j+1]=key;
  34.     }
  35. }
  36.  
  37. int main()
  38. {
  39.     int tc;
  40.     cout<<"Total Currency you have: ";
  41.     cin>>tc;
  42.     int coin[tc];
  43.     cout<<"Currency you have: ";
  44.     for(int i=0;i<tc;i++){
  45.         cin>>coin[i];
  46.     }
  47.     sort(coin,tc);
  48.     int n=tc;
  49.     cout<<"Your Friends amount: ";
  50.     int v;
  51.     cin>>v;
  52.     int c = conchange(coin,tc,v);
  53.     cout<<"Amount of coins: "<<c<<endl;
  54.     cout<<"All coins: ";
  55.     for(int i = 0; i < c; i++)cout<<a[i]<<" ";
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement