mov cx,100 xor ax,ax Acculate:test cx,1 jnz next ;奇数,不累加 add ax,cx ;偶数,累加 next:loop Acculate mov SUM,ax ;保存
编程计算1100的所有偶数的和,结果保存到SUM中
mov cx,100
xor ax,ax
Acculate:
test cx,1
jnz next ;奇数,不累加
add ax,cx ;偶数,累加
next:
loop Acculate
mov SUM,ax ;保存2009-12-30
你没要求用什么语言,我就用VB编一个哈
private sub test()
dim i as integer,res as long
for i=2 to 100 step 2
res=res+i
next i
print res
end sub2009-12-30
应该要的是java的吧
public class Sum{
public static void main(String[] args){
int sum=0;
for(int i=0;i<=100;i++){
if(i%2==0){
sum+=i;
}
}
System.out.println(sum);
}
}2009-12-30