小编Ale*_*les的帖子

OR和少于运算符不能用作预期的C语言

我正在练习一本名为C语言编程的书,尝试解决练习7.9,所以我的代码完美运行,直到我为函数添加一个条件语句,只接受大于0的变量

我试过在很多方面改变它,但似乎没有任何效果

// Program to find the least common multiple
#include <stdio.h>

int main(void)
{
 int lcm(int u, int v);

 printf("the least common multiple of 15 and 30 is: %i\n", lcm(15, 30));

 return 0;
 }
// Least common multiple
int lcm(int u, int v)
{
 int gcd(int u, int v);

 int result;

 if (v || u <= 0)
 {
    printf("Error the values of u and v must be greater than 0");
    return 0;
 }

 result = (u * v) / …
Run Code Online (Sandbox Code Playgroud)

c logical-operators relational-operators

0
推荐指数
1
解决办法
132
查看次数