分别用while\do while和for实现0—200以内的奇数的累加和

来源:百度知道 编辑:UC知道 时间:2024/06/01 08:07:30
分别用while\do while和for实现0—200以内的奇数的累加和

int temp;
for(int i; i <= 200;i++)
{
if(i%2!=0)
{
temp + i = temp;
}
} 这个是for...

int = 0;
while(i <= 200)
{
if(i%2!=0)
{
temp + i = temp;
}
i++;
} 这个是while

int i = 0;
do{
if(i%2!=0)
{
temp + i = temp;
}
i++;
}while(i < 200) 这个是 do-while

我没有用编译器,你看一下,我觉得应该是对的,如果还有什么不懂的,你可以把我加为好友,看还有什么我可以帮你的。。。。。。。。。

-----------while---------
dim i,a
i=1
a=0
while i<200
a=a+i
i=i+2
wend

-----------do while---------
dim i,a
i=1
a=0
do while i<200
a=a+i
i=i+2
loop

------------for-----------
for i=1 to 200 Step 2
a=a+i
next