使用for循环结构编写程序计算1到100之间的奇数之和、偶数之和,输出格式为“1到100奇数和=xxx;

2024-11-27 16:40:13
推荐回答(3个)
回答(1):

Private Sub Command1_Click()
    Dim s As Long
    Dim i As Integer, j As Integer
    s = 0
    Print "100-500之间的奇数为:"
    For i = 101 To 500 Step 2
        Print i;
        j = j + 1
        If j Mod 10 = 0 Then Print
        s = s + i
    Next i
    Print "奇数的和为"; s
End Sub

回答(2):

int jishuhe = 0;
int oushuhe = 0;
for (int i=1; i<=100; i++)
{
if (i % 2 == 0)
{
oushuhe += i;
}
else
{
jishuhe += i;
}
}

输出自己写吧

回答(3):

2500