6匹一拖三格力空调价格:在1至100中,既不能被2整除,又不能被3整除的数有几个?

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/28 18:38:17

33。
被2整除的有50个,被3整除的33个,其中被6整除的16个被重复算了,所以能被2或3整除的有50+33-16=67个,因此结果为100-67=33。

用ASP做出来的:
<%
for i = 1 to 100

if i mod 2 <>0 and i mod 3 <> 0 then
sum=sum+1
response.Write(i & ",")
end if
next
response.Write("<br>共有" & sum & "条记录符合要求。")
%>
运行结果:
1,5,7,11,13,17,19,23,25,29,31,35,37,41,43,47,49,53,55,59,61,65,67,71,73,77,79,83,85,89,91,95,97,
共有33条记录符合要求。

dim count
for i= 1 to 100
if i mod 2<>0 and i mod 3<>0 then count=count+1
next

msgbox count
就是这个count得到33个

luflaworgu 的程序我怎么看也不像是 c 语言的呀

c 语言程序这样写

#include <stdio.h>

int main ( void )
{
int i, j = 0;

for ( i = 1; i <= 100; i ++ )
if ( i%2 && i %3 ) j ++;

printf ( "numbers in [1-100] and cannot be divided by 2 and 3 is: %d\n", j );
return 0;
}

include i;
for(i=1,i<=100,i++)
if(if i mod 2<>0 and i mod 3<>0 then count=count+1)
next
printf("%d",count)
所以用C语言做出来是33

100/6=16.67
16个