1. 程式人生 > >100以內1-2+3-4+...+99-100和為:

100以內1-2+3-4+...+99-100和為:

count=1
s = 0
while count<101:
    temp=count%2
    if temp==0:
        s=s-count
    else:
        s=s+count
    count=count+1
print('100以內1-2+3-4+...+99-100和為:',s)
print('-----end-----')

 

輸出結果為:

100以內1-2+3-4+...+99-100和為: -50
-----end-----