问答详情
源自:3-2 算术运算符

为啥错了!

#include <stdio.h>

int main()

{

    int x,y;

    x = 10;

    y = -3;

    printf("x+y=%d\n",x+y);  

    printf("x-y=%d\n",x-y);

    printf("x*y=%d\n",x*y);

    printf("x/y=%d\n",x/y);

    printf("x%y=%d\n",x%y);

    return 0;    

}


提问者:weixin_慕妹9028574 2021-08-09 15:27

个回答

  • 慕的地6500282
    2021-08-09 16:19:09

    应该是括号里的%被默认为符号了,再加上一个试试

  • 慕的地6500282
    2021-08-09 16:15:18

    #include <stdio.h>int main(){    int x,y;    x = 10;    y = -3;    int re1,re2,re3,re4,re5;    re1=x+y;    re2=x-y;    re3=x*y;    re4=x/y;    re5=x%y;    printf("x+y=%d\n",re1);      printf("x-y=%d\n",re2);    printf("x*y=%d\n",re3);    printf("x/y=%d\n",re4);    printf("x%%y=%d\n",re5);      return 0;    }