当前位置: 代码迷 >> C语言 >> S=1+2+4+8+16+......,直到s
  详细解决方案

S=1+2+4+8+16+......,直到s

热度:340   发布时间:2007-09-14 12:45:42.0
S=1+2+4+8+16+......,直到s
那里错了?????

#include <math.h>
#include <stdio.h>
main()
{
int n=1,s=1;
while(s+n<=100)
{
n=2*n;
s=s+n;
}
printf("%d",s);
}


[此贴子已经被作者于2007-9-14 12:56:39编辑过]

搜索更多相关的解决方案: include  

----------------解决方案--------------------------------------------------------
好像没错
----------------解决方案--------------------------------------------------------
是不是你题错了
----------------解决方案--------------------------------------------------------

自己改过来了,正确了,,,呵呵 !


#include <math.h>
#include <stdio.h>
main()
{
int n=1,s=0;
while(s+n<=100)
{
s=s+n;
n=2*n;
}
printf("%d",s);
getchar();
return 0;

}

[此贴子已经被作者于2007-9-14 13:15:18编辑过]


----------------解决方案--------------------------------------------------------
  相关解决方案