打印方程(a+b) <= n 中‘a’的值,并且 a+b 可被 x 整除
在给定的等式程序中,必须找到‘a’的值,其中 a+b<=n 且也可被 x 整除。
算法
START Step 1 -> Declare start variables b=10, x=9, n=40 and flag=0, divisible Step 2 -> Loop For divisible = (b / x + 1 ) * x and divisible <= n and divisible += x IF divisible - b >= 1 Print divisible-1 Set flag=1 End END STOP
示例
#include <stdio.h> int main(int argc, char const *argv[]) { int b=10, x=9, n=40, flag = 0; int divisible; for (divisible = (b / x + 1 ) * x ; divisible <= n; divisible += x) { if ( divisible - b >= 1) { printf("%d ", divisible - b ); flag = 1; } } return 0; }
输出
如果我们运行以上程序,它将生成以下输出
8 17 26
广告