编程求100到200之间既能被3整除又能被5整除的正整数个数,并显示这些数

2025-04-09 15:34:20
推荐回答(3个)
回答1:

for($i = 100;$i<=200;$i++){
if($i%3 ==0 and $i%5==0){
echo $i.'
';
}
}
?>
这是PHP的,因为你没说你需要用啥语言写

回答2:

java实现的:
其他语言解决思路类似:

public class Test2 {

/**
* @param args
*/
public void test1(){
int count=0;
for(int i=100;i<=200;i++){
if((i%3==0) && (i%5==0)){
count++;
System.out.println(i);
}
}
System.out.println("共有:"+count+"个");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Test2 test2 =new Test2();
test2.test1();
}

}

回答3:

int n=0;//记录个数
for(int a=100;a<201;a++)
{
if(a%3==0&&a%5==0)
{
printf(“%d\n”,a);
n++;
}
}