如何从另一个整数中减去两个整数之和然后递增呢?

时间:2017-10-06 16:13:57

标签: c++

如何从z中减去x和y的总和,然后在C ++中的单个语句中递增它

int main()
{
int x,y,z,p;
x=5;
y=6;
z=20;
p=z-(x+y)++;
cout<<"value of p="<<p;
}

它显示错误为增量操作数所需的值

3 个答案:

答案 0 :(得分:1)

Subtract that sum, reduced by 1, using -= : z -= (x + y - 1)

#include <iostream>
int main()
{
    int x, y, z;
    x = 5;
    y = 6;
    z = 20;

    z -= (x + y - 1);

    std::cout << "value of z=" << z;
}

http://coliru.stacked-crooked.com/a/18725dc9ac027784

答案 1 :(得分:0)

#include <iostream>
int main() {
   int x,y,f,z;
   f=(x=10, y=5, z=20, z-(x+y)+1);
   std::cout << "result is = "<<f ;
}

答案 2 :(得分:-1)

增量只是意味着添加1,因此nlist[0][0]与使用Postfix增量运算符一样有效