用C语言编程:统计1-200中,能够分别被2,3整除,但不能同时被2,3整除的数的个数

2024-10-30 21:48:24
推荐回答(5个)
回答1:

main()
{
int i,n=0;
for(i=1;i<=200;i++)
if(((i%2==0)&&(i%3!=0))||((i%2!=0)&&(i%3==0)))
n++;
printf("%d",n);
}
小问题有那么麻烦吗?

回答2:

#include
define N 2000
fun(int N)
{
int i,count;
for (i=0;i<=N;i++)
if ((i%2==0||i%3==0)&&(i%6!=0))
count++;
return count
}
main()
{
printf("%d",fun(N));
}

回答3:

#include
void main()
{int i,j=0;
int a[30];
for(i=1;i<=200;i++)
{if(i%2==0||i%3==0&&i%2%3!=0)a[j++]=i;}
printf("there are %d numbers\n",j);
printf("the numbers are:\n");
for(i=0;i{printf("%d ",a[i]);}
}

回答4:

#include
int main()
{
int i,count2,count3;
count2=0;
count3=0;
for(i=1;i<=200;i++)
{
if((i%2==0)&&(i%3!=0))
count2++;
if((i%3==0)&&(i%2!=0))
count3++;
}
printf("count2=%d count3=%d\n",count2,count3);
return 0;
}

回答5:

int count=0;
for(int i=1;i<=200;i++)
{
if(i%2==0||i%3==0)
{
if(i%2==0&&i%3!=0)
count++;
if(i%2!=0&&i%3==0)
count++;
}
}
printf("%d",i);