编程求出1—100之间能被3或7整除的数的平方和

2024-11-06 03:44:26
推荐回答(3个)
回答(1):

#include
int main()

{
int i,sum=0;
for(i=0;i<100;i++)
if((!(i%3))||(!(i%7)))
sum+=i*i;
printf("%d\n",sum);
return 0;
}

回答(2):

Private Sub Command1_Click()
Dim i, j, sum As Integer
For i = 1 To 100
j = i Mod 21
If j = 0 Then sum = sum + i ^ 2

Next i
Print sum '打印和
End Sub

回答(3):

Private Sub Command1_Click()
Dim i, j, sum As Long
sum = 0
For i = 1 To 100
If (i Mod 3 = 0) Or (i Mod 7 = 0) Then sum = sum + i ^ 2
Next i
Print sum
End Sub