编出完整程序,求出1~100之间,所有能被3整除但不能被7整除的整数之和。

2024-12-02 02:59:55
推荐回答(4个)
回答1:

#include "stdio.h"
void main()
{
int i,sum=0;
for(i=3;i<=100;i+=3)
if(i%7!=0)
{
printf("%d能被3整除,并且不能被7整除\n",i);
sum+=i;
}
printf("这些数字的和为:%d",sum);
}

回答2:

#include
int main()
{
int sum=0,i;
for(i=1;i<101;i++)
{
if(i%3==0 && i%7!=0)
sum+=i;
}
printf("%d",sum);
}

回答3:

Private Sub Command1_Click()
Dim i As Integer
For i = 7 To 100 Step 7
If i Mod 3 = 0 Then Print i;
Next
Print
i = 7
Do While i < 100
If i Mod 3 = 0 Then Print i;
i = i + 7
Loop
Print
i = 7
Do
If i Mod 3 = 0 Then Print i;
i = i + 7
Loop Until i > 100
Print
End Sub

回答4:

#include

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