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

/*
    filename:  ex02.c
    
    21天C语言代码训练营(第二天)
    //www.greatytc.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;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容