美文网首页
21天C语言代码训练营 —— 练习2

21天C语言代码训练营 —— 练习2

作者: 阿债 | 来源:发表于2016-04-30 07:03 被阅读13次
    /*
        filename:  ex02.c
        
        21天C语言代码训练营(第二天)
        http://www.jianshu.com/p/9e321ae3cd08
        
        计算出x + 2y + 3z = 100这个方程的所有解。
    */
    
    #include <stdio.h>
    #define TOTAL 100
                /*最小系数必须为1*/
    #define FAC_Y 2 /*中等系数*/
    #define FAC_Z 3 /*最大系数*/
    
    int main()
    {
        int x, y, z, subtotal;
        z = TOTAL / FAC_Z;
        for (; z >= 0; z--) {
            subtotal = TOTAL - FAC_Z * z;
            y = subtotal / FAC_Y;
            x = subtotal % FAC_Y;
            for (; x <= subtotal; ) {
                printf("x = %d, y = %d, z = %d\n", x, y, z);
                y--;
                x += FAC_Y;
            }
        }
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:21天C语言代码训练营 —— 练习2

          本文链接:https://www.haomeiwen.com/subject/tgrkrttx.html