用c语言求s不超过1000时,n的最大值,s=1+2+3+...+n

用C语言,求帮助

第1个回答  2011-11-16
#include <stdio.h>
void main()
{
int n=1,s=0;
while(s<1000)
s+=n++;
printf("n=%d\n",n-1);
}本回答被提问者采纳
第2个回答  2011-11-16
#include <stdio.h>

int main(void)
{
int i;
int s = 0;
for (i = 1; ;i++)
{
s+= i;
if (s > 1000)
break;
}

printf("%d", i - 1);
}
第3个回答  2011-11-16
#include<stdio.h>
main()
{int s=0,n=1;
while(s<=1000)
{s+=n;n++;}
printf("n=%d",n);}
第4个回答  2011-11-16
s=0
i=0;
while(s<=1000)
{
s+=s+1;
i++;
}
相似回答