样式
代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="huyiwei">
<title>1~1000能被7和9同时整除</title>
</head>
<body>
<h3>
找出1~1000之间能够被7和9同时整除的整数的个数及累加和
</h3>
<script type="text/javascript">
var flag = 5;
var count = 0;
var sum = 0;
document.write("区间中符合条件的数有(输出格式:5个1行):"+'<br/>');
for(var i = 1 ; i <= 1000 ; i++){
if(i%7 == 0 && i%9 == 0){
document.write(i+'\t');
count++;
sum += i;
flag--;
if(flag==0){
document.write('<br/>');
flag = 5;
}
}
}
document.write("区间中符合条件的数共有"+count+"个");
document.write('<br/>');
document.write("区间中符合条件的数的累加和为"+sum);
</script>
</body>
</html>