#include <stdio.h>
int main()
{
int a,b
b=0
for(a=1a<=100a+=1)
b=b+a
printf("sum = %d\n",b)
return 0
}
扩展资料:
使用java的编程方法得到1-100的和:
package study01
public class TestWhile {
public static void main(String[] args)
{
int sum = 0
int i = 1
while (i <= 100)
{
System.out.println(i)
sum += i
i++
}
System.out.println(sum)
}
}
结果等于:5050。
declare @iSum intdeclare @iCount int
select @iSum = 0
select @iCount = 1
while @iCount <= 100
begin
select @iSum = @iSum + @iCount
select @iCount = @iCount + 1
end
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)