在条件可能的分配(C) [英] possible assignment in condition (C)

查看:192
本文介绍了在条件可能的分配(C)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要找到的是数字一两位数奇怪。错误亮起,如果

 的#include<&stdio.h中GT;
main()的
{
    诠释A,K;
    诠释计数= 0;
    的printf(输入号码\\ n,一);
    scanf函数(%d个,&安培; A);
    K =%2;
    而(一)
    {
        一个/ = 10;
        算上++;
    }
    如果(K = 1和;&放大器;计数= 2)
        的printf(它的\\ n);
    其他
        的printf(这不是的\\ n);
    返回(0);
}


解决方案

该错误是在这里:

 如果(K = 1&安培;&放大器;计数= 2)

你可能是指:

 如果(K == 1安培;&放大器;计数== 2)

= 是一个赋值。 == 是平等的比较。

此外,该环是没有必要的。可以检查的数量是两个数字通过检查它是否小于100和大于或等于10。

I have to find is the number "a" a two-digit odd. Mistake comes on if

#include <stdio.h>
main ()
{
    int a,k;
    int count=0;
    printf ("input number \n", a);
    scanf ("%d", &a);
    k = a % 2;
    while (a)
    {
        a /= 10;
        count ++;
    }
    if (k = 1 && count = 2)
        printf ("It is \n");
    else
        printf ("It is not \n");
    return (0);
}

解决方案

The error is here:

if (k = 1 && count = 2)

you probably meant:

if (k == 1 && count == 2)

= is an assignment. == is a comparison for equality.

Also, the loop is not necessary. You can check if the number is two digits by checking if it's less than 100 and greater than or equal to 10.

这篇关于在条件可能的分配(C)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆