SHARE
TWEET

Untitled

a guest Jun 16th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. void insertion_sort(int a[],int n)
  3. {
  4.     int i,j;
  5.     for(j=1; j<n; j++)
  6.     {
  7.         int key =a[j];
  8.         i=j-1;
  9.         while(i>=0 && a[i]<=key)
  10.         {
  11.             a[i+1]=a[i];
  12.             i--;
  13.         }
  14.         a[i+1]=key;
  15.     }
  16.  
  17.     for(i=0; i<n; i++)
  18.     {
  19.         printf("%d ",a[i]);
  20.     }
  21.     printf("coins are sorted!\n");
  22. }
  23. int main()
  24. {
  25.     int s,num;
  26.     printf("Enter your amount: ");
  27.     scanf("%d",&s);
  28.  
  29.     int m,i;
  30.     printf("how many coin: ");
  31.  
  32.     scanf("%d",&m);
  33.     int c[m];
  34.     printf("enter coin values: ");
  35.     for(i=0; i<m; i++)
  36.     {
  37.         scanf("%d",&c[i]);
  38.     }
  39.     insertion_sort(c,m);
  40.  
  41.  
  42.             i=0;
  43.             while(s>0)
  44.             {
  45.                 if(s>=c[i])
  46.             {
  47.                 num = s/c[i];
  48.                 printf("%d coin will need %d\n",c[i],num);
  49.                 s = s - num*c[i];
  50.             }
  51.             i++;
  52.             }
  53.  
  54.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top