c语言(循环)

用一角、两角、五角这三种面值的钱组合成若干元。

    #include <stdio.h>
    int main(){
        int x=2;
        int one,two,five;
        for(one=1;one<x*10;one++){
            for(two=1;two<x*10/2;two++){
                for(five=1;five<x*10/5;five++){
                    if(one + two*2 + five*5==x*10){
                        printf("可以用%d个1角%d个2角%d个5角组成%d元\n",
                        one,two,five,x);
                    }
                }
            }
        }
    }

猜你喜欢

转载自blog.csdn.net/u010075989/article/details/53708216