您好,欢迎来到二三四教育网。
搜索
您的当前位置:首页21天C语言代码训练营 —— 练习2

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

来源:二三四教育网
/*
    filename:  ex02.c
    
    21天C语言代码训练营(第二天)
    
    
    计算出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;
}

Copyright © 2019- how234.cn 版权所有 赣ICP备2023008801号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务