C语言循环语句没有按照循环条件终止

想问问循环条件这么写为何程序不会终止?

img

while (answer != ture && 0<j<3)
            {
                j++;
                printf("答错了\t请再输入一次\t你还有%d次机会", 3 - j);
                scanf_s("%d", &answer);
            }

哪有0<j<3这样的,要写成(j>0&&j<3)

  • 你可以看下这个问题的回答https://ask.csdn.net/questions/220718
  • 你也可以参考下这篇文章:在C语言中使用枚举法解决填运算符问题
  • 除此之外, 这篇博客: C语言程序设计例题习题复试机考中的 写一个计算调和级数部分和的程序。 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • #include<stdio.h>
    //方法一
    int main()
    {
        int n;
        scanf("%d",&n);
        double sum;
        for(int i=1; i<=n; i++)
        {
            sum += 1.0/double(i);
        }
        printf("%f\n",sum);
        return 0;
    }
    /*
    10
    2.928968
    
    Process returned 0 (0x0)   execution time : 3.110 s
    Press any key to continue.
    */
    
    
    #include<stdio.h>
    int x,y;
    int gcd(int a, int b)
    {
        if(b==0) return a;
        return gcd(b, a%b);
    }
    void add(int a1, int b1,int a2, int b2)
    {
        x = a1*b2+a2*b1;
        y = b1*b2;
        int temp;
        if(x>y)
            temp = gcd(x,y);
        else
            temp = gcd(y,x);
        //printf("%d/%d\   %dn", x,y, );
        x = x/temp;
        y = y/temp;
    }
    //方法二结果为分数
    int main()
    {
        int n;
        scanf("%d",&n);
        x=1,y=1;
        for(int i=2; i<=n; i++)
        {
            add(x,y,1,i);
        }
        printf("%d/%d\n",x,y);
        return 0;
    }
    /*
    10
    7381/2520
    
    Process returned 0 (0x0)   execution time : 1.452 s
    Press any key to continue.
    
    */