为了账号安全,请及时绑定邮箱和手机立即绑定

为什么++i和I++的结果会是一样的呢

#include <stdio.h>

int main()

{

    int i,sum=0;

    i=1;

    while(i<=100)  //循环条件应该是什么呢?

    {

        sum=sum+i;

         i++ ;       //这里是不是应该改变循环变量的值

    }

    printf("100以内所有整数之和为:%d\n", sum);

    return 0;

}

#include <stdio.h>

int main()

{

    int i,sum=0;

    i=1;

    while(i<=100)  //循环条件应该是什么呢?

    {

        sum=sum+i;

         i++ ;       //这里是不是应该改变循环变量的值

    }

    printf("100以内所有整数之和为:%d\n", sum);

    return 0;

}


正在回答

7 回答

http://physics.scu.edu.cn/search ... 1%6C%71%77%6E%71%77
http://physics.scu.edu.cn/search ... 3%7A%65%76%79%70%65
http://physics.scu.edu.cn/search ... 5%6B%64%77%73%7A%64
http://physics.scu.edu.cn/search ... 0%91%7A%62%7A%73%6B
http://physics.scu.edu.cn/search ... 1%73%69%6E%72%6E%74
http://physics.scu.edu.cn/search ... 0%91%71%6D%71%67%6E
http://physics.scu.edu.cn/search ... 5%77%61%65%74%79%6E
http://physics.scu.edu.cn/search ... 3%61%6D%74%75%62%68
http://physics.scu.edu.cn/search ... 4%72%6D%73%7A%74%77
http://physics.scu.edu.cn/search ... 0%91%73%61%70%65%76
http://physics.scu.edu.cn/search ... 1%62%64%79%6F%6A%6F
http://physics.scu.edu.cn/search ... 1%72%66%75%6C%61%74
http://physics.scu.edu.cn/search ... 1%6B%79%63%76%78%79
http://physics.scu.edu.cn/search ... 5%78%61%64%75%69%78
http://physics.scu.edu.cn/search ... 1%64%6A%62%69%79%62
http://physics.scu.edu.cn/search ... 5%79%72%77%70%76%65
http://physics.scu.edu.cn/search ... A%6F%65%73%75%69%6C
http://physics.scu.edu.cn/search ... 3%79%69%71%69%6D%73
http://physics.scu.edu.cn/search ... A%62%6B%6F%73%6C%66
http://physics.scu.edu.cn/search ... 0%91%73%72%77%69%6A
http://physics.scu.edu.cn/search ... A%6F%75%6F%66%77%73
http://physics.scu.edu.cn/search ... 0%91%6D%77%63%68%6B
http://physics.scu.edu.cn/search ... 8%74%69%6C%74%75%6A
http://physics.scu.edu.cn/search ... 1%70%71%7A%64%68%61
http://physics.scu.edu.cn/search ... 0%91%6C%7A%65%76%72
http://physics.scu.edu.cn/search ... 6%71%66%68%76%6B%61
http://physics.scu.edu.cn/search ... 1%6C%61%67%77%67%76
http://physics.scu.edu.cn/search ... 0%91%6E%6B%74%77%78
http://physics.scu.edu.cn/search ... D%6B%72%6A%70%69%7A
http://physics.scu.edu.cn/search ... 7%6C%7A%74%69%6F%72
http://physics.scu.edu.cn/search ... 6%75%79%62%66%6D%6F
http://physics.scu.edu.cn/search ... A%68%6C%70%67%77%79
http://physics.scu.edu.cn/search ... 1%74%75%6A%79%79%62
http://physics.scu.edu.cn/search ... B%78%62%65%68%6B%6C
http://physics.scu.edu.cn/search ... 1%79%7A%64%79%6D%6E
http://www.ie.sjtu.edu.cn/?s=%E6 ... 1%62%76%63%69%73%6C
http://physics.scu.edu.cn/search ... 0%91%75%63%6C%71%73
http://www.ie.sjtu.edu.cn/?s=%E6 ... 4%79%62%68%6B%6C%62
http://physics.scu.edu.cn/search ... 5%70%67%78%61%65%68
http://www.ie.sjtu.edu.cn/?s=%E8 ... F%61%71%68%6C%75%7A
http://physics.scu.edu.cn/search ... 3%72%68%69%6B%6C%62
http://www.ie.sjtu.edu.cn/?s=%E5 ... 0%91%78%78%65%79%65
http://physics.scu.edu.cn/search ... 6%66%6A%7A%70%65%75
http://www.ie.sjtu.edu.cn/?s=%E6 ... 1%77%72%79%72%78%71
http://physics.scu.edu.cn/search ... 1%76%6C%6D%6F%75%68
http://www.ie.sjtu.edu.cn/?s=%E9 ... 0%91%72%7A%73%6A%64
http://physics.scu.edu.cn/search ... A%78%7A%66%74%69%78
http://physics.scu.edu.cn/search ... 8%6F%72%68%78%61%69
http://www.ie.sjtu.edu.cn/?s=%E9 ... D%65%68%78%7A%61%71
http://physics.scu.edu.cn/search ... 2%67%78%6F%72%76%6F
http://www.ie.sjtu.edu.cn/?s=%E6 ... 2%78%71%76%6C%6E%64
http://physics.scu.edu.cn/search ... 1%76%66%75%69%6A%78
http://www.ie.sjtu.edu.cn/?s=%E6 ... 9%74%62%68%61%79%64
http://physics.scu.edu.cn/search ... 1%69%78%71%6A%7A%72
http://www.ie.sjtu.edu.cn/?s=%E8 ... 0%91%77%64%75%79%64
http://www.ie.sjtu.edu.cn/?s=%E5 ... 1%78%71%69%7A%6A%7A
http://www.ie.sjtu.edu.cn/?s=%E5 ... 1%77%68%7A%73%70%6A
http://physics.scu.edu.cn/search ... 0%91%6B%78%70%75%6D
http://www.ie.sjtu.edu.cn/?s=%E6 ... 1%77%70%73%6E%61%63
http://physics.scu.edu.cn/search ... 1%67%78%71%68%67%79
http://www.ie.sjtu.edu.cn/?s=%E9 ... 3%75%6D%62%65%74%78
http://physics.scu.edu.cn/search ... 0%75%6E%74%6C%64%76
http://www.ie.sjtu.edu.cn/?s=%E6 ... 1%77%67%6D%73%6B%64
http://physics.scu.edu.cn/search ... 1%75%78%72%6B%63%75
http://www.ie.sjtu.edu.cn/?s=%E4 ... 5%6A%6E%70%66%76%6B
http://physics.scu.edu.cn/search ... 0%91%68%63%72%77%6B
http://www.ie.sjtu.edu.cn/?s=%E7 ... 1%75%67%6D%74%6D%66
http://physics.scu.edu.cn/search ... 6%7A%62%71%67%6E%71
http://www.ie.sjtu.edu.cn/?s=%E8 ... 9%7A%67%6E%68%6E%67
http://physics.scu.edu.cn/search ... 0%91%76%62%74%77%63
http://www.ie.sjtu.edu.cn/?s=%E9 ... 1%74%79%77%6F%69%63
http://physics.scu.edu.cn/search ... 4%67%68%6C%64%73%68
http://www.ie.sjtu.edu.cn/?s=%E9 ... 0%91%6C%61%75%73%6C
http://physics.scu.edu.cn/search ... 1%76%61%67%69%77%7A
http://physics.scu.edu.cn/search ... 1%61%6F%67%6B%6E%66
http://www.ie.sjtu.edu.cn/?s=%E6 ... F%71%74%69%63%72%67
http://physics.scu.edu.cn/search ... A%64%77%6F%66%77%6E
http://www.ie.sjtu.edu.cn/?s=%E5 ... 0%91%61%6C%73%76%6E
http://physics.scu.edu.cn/search ... 1%76%6A%70%67%6B%70
http://www.ie.sjtu.edu.cn/?s=%E6 ... 8%78%73%6C%66%6D%73
http://physics.scu.edu.cn/search ... 1%6B%62%66%6A%6B%62
http://www.ie.sjtu.edu.cn/?s=%E6 ... 1%75%77%64%69%6C%70
http://physics.scu.edu.cn/search ... 1%6D%73%69%65%76%6F
http://www.ie.sjtu.edu.cn/?s=%E6 ... 0%91%74%65%74%78%72
http://physics.scu.edu.cn/search ... 2%61%65%75%6C%6F%65
http://www.ie.sjtu.edu.cn/?s=%E6 ... 5%6E%72%6E%71%73%6C
http://physics.scu.edu.cn/search ... 0%91%62%6E%64%74%6C
http://www.ie.sjtu.edu.cn/?s=%E8 ... 1%70%68%6D%71%68%7A
http://www.ie.sjtu.edu.cn/?s=%E5 ... 0%91%6A%64%79%61%70
http://physics.scu.edu.cn/search ... 2%74%68%76%6F%62%63
http://www.ie.sjtu.edu.cn/?s=%E4 ... 7%68%76%6C%7A%73%68
http://physics.scu.edu.cn/search ... 6%64%77%65%74%76%6C
http://www.ie.sjtu.edu.cn/?s=%E5 ... 2%72%72%68%77%6B%79
http://physics.scu.edu.cn/search ... C%76%6E%6D%65%79%70
http://www.ie.sjtu.edu.cn/?s=%E9 ... A%6A%63%73%77%6E%66
http://physics.scu.edu.cn/search ... 0%91%62%68%6C%6F%71
http://www.ie.sjtu.edu.cn/?s=%E5 ... A%6A%6C%6F%71%74%6F
http://physics.scu.edu.cn/search ... 5%6F%6C%6B%6F%64%6C
http://www.ie.sjtu.edu.cn/?s=%E4 ... 3%75%76%63%73%67%69
http://physics.scu.edu.cn/search ... 0%91%65%77%71%73%74
http://www.ie.sjtu.edu.cn/?s=%E7 ... 9%64%73%67%7A%6F%63
http://physics.scu.edu.cn/search ... 7%71%66%77%6D%63%71
http://www.ie.sjtu.edu.cn/?s=%E8 ... 1%6B%64%73%79%61%62
http://physics.scu.edu.cn/search ... 0%91%78%6A%79%7A%6F
http://www.ie.sjtu.edu.cn/?s=%E9 ... 0%91%66%6F%73%70%74
http://physics.scu.edu.cn/search ... 0%91%71%70%72%74%69
http://www.ie.sjtu.edu.cn/?s=%E5 ... A%71%6A%7A%6E%62%77
http://www.ie.sjtu.edu.cn/?s=%E6 ... D%76%7A%64%74%6A%6D
http://physics.scu.edu.cn/search ... D%6B%6D%6F%64%79%6D
http://www.ie.sjtu.edu.cn/?s=%E5 ... 8%70%65%73%69%6C%6F
http://physics.scu.edu.cn/search ... 1%76%62%71%67%78%6C
http://www.ie.sjtu.edu.cn/?s=%E6 ... F%69%6D%76%61%72%74
http://physics.scu.edu.cn/search ... 8%6D%63%70%64%72%66
http://www.ie.sjtu.edu.cn/?s=%E6 ... B%62%6A%6C%62%64%68
http://physics.scu.edu.cn/search ... 1%75%62%65%68%6A%6C
http://www.ie.sjtu.edu.cn/?s=%E6 ... 7%62%65%72%67%70%67
http://physics.scu.edu.cn/search ... E%6F%67%6B%7A%70%6D
http://www.ie.sjtu.edu.cn/?s=%E6 ... 9%73%79%6F%66%75%6A
http://physics.scu.edu.cn/search ... 4%70%73%69%6D%69%78
http://www.ie.sjtu.edu.cn/?s=%E8 ... 1%65%78%61%66%64%68
http://physics.scu.edu.cn/search ... 4%77%6D%61%68%69%69
http://www.ie.sjtu.edu.cn/?s=%E5 ... 1%77%72%75%6A%6C%6E
http://physics.scu.edu.cn/search ... 1%78%65%67%6A%79%64


0 回复 有任何疑惑可以回复我~
i++先使用,再运算。反之,先运算,再使用。
0 回复 有任何疑惑可以回复我~

这样就不一样了

sum = sum + i++;
sum = sum + ++i


0 回复 有任何疑惑可以回复我~

c程序是按顺序从上往下一步步走的,”i++;“是一个单独的代码程序,不管是++i还是i++,没到这排代码之前,i的值该多少就是多少,过了这排代码之后i的值才加1.意思大概就是这么个意思吧呵呵

0 回复 有任何疑惑可以回复我~

我是试着改了下,将i++改成++i,输出结果还是一样,所以不明为什么会一样。

0 回复 有任何疑惑可以回复我~

你的两段代码都是一样的!++i是先运算再使用i;i++是先使用i,再运算,不一样的。除非是程序语句没多大变化,从而两种写法都不影响输出结果。

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什么++i和I++的结果会是一样的呢

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信