求C++在100到200中找出同时满足用3除余2,用5除余3和用7除余2的所有整数。帮忙考试用
来源:百度知道 编辑:UC知道 时间:2024/07/04 23:37:48
for(i=100;i<=200;i++)
if(i%3==2&&i%5==3&&i%7==2)cout<<i<endl;
for(int i=100;i<=200;i++)
{if(i%3==2)printf("除3余2的有%d\n",i);}
for(int i=100;i<=200;i++)
{if(i%5==3)printf("除5余3的有%d\n",i);}
for(int i=100;i<=200;i++)
{if(i%7==2)printf("除7余2的有%d\n",i);}
可以么?
for(i=100;i<=200;i++)
if(i%3==2&&i%5==3&&i%7==2)cout<<i<endl;
#include<iostream>
using namespace std;
int main()
{
for(int i = 100; i < 200; i++)
{
if((i % 3 == 2) && (i % 5 == 3) && (i % 7 == 2))
{
cout << i << endl;
}
}
return 0;
}