Find the least number of coins required that can make any change from 1 to 99 cents

后端 未结 27 2261
生来不讨喜
生来不讨喜 2020-12-07 10:08

Recently I challenged my co-worker to write an algorithm to solve this problem:

Find the least number of coins required that can make any change from

27条回答
  •  天涯浪人
    2020-12-07 10:40

    Example Program:

    #include 
    
        #define LEN 9 // array length
        int main(){
            int coins[LEN]={0,0,0,0,0,0,0,0,0}; // coin count
            int cointypes[LEN]={1000,500,100,50,20,10,5,2,1}; // declare your coins and note here {ASC order}   
            int sum =0; //temp variable for sum
            int inc=0; // for loop
            int amount=0; // for total amount
            printf("Enter Amount :");
            scanf("%d",&amount);
            while(sum

提交回复
热议问题