Open ccckmit opened 3 years ago
陳鍾誠繳交範例
檔案 : star.js
function star(n) {
for (var i=0; i<n; i++)
console.log('*')
}
star(5)
執行結果
(base) csienqu-teacher:02 csienqu$ deno run star.js
*
*
*
*
*
function star(n){
for(var i=0;i<n;++i)console.log("*")
}
function between(l,r){
for(var i=l;i<=r;++i)console.log(i)
}
star(5)
between(3,8)
執行結果
*
*
*
*
*
3
4
5
6
7
8
檔案star.js 作業1
function star(n)
{
for(var i=0;i<n;i++)
console.log('*')
}
star(5)
執行結果
PS C:\課程\wp109b\deno\homework> deno run homework.js
*
*
*
*
*
作業2
function star(n)
{
for(var i=3;i<=8;i++)
console.log(i)
}
star()
執行結果
PS C:\課程\wp109b\deno\homework> deno run homework.js
3
4
5
6
7
8
110910509 蔡宗霖
檔案 hw2.js
function star(n) {
for (var i=0; i<n; i++)
console.log('*')
}
function between(x,y){
for (var i=x; i<=y; i++ )
console.log(i)
}
star(5)
between(3,8)
執行結果
KentdeAir:02 kenttsai$ deno run hw2.js
*
*
*
*
*
3
4
5
6
7
8
檔案 hw2p.js
function isprime(n){
for (var i=2; i<n;i++){
if(n%i==0){
return false;
}
};
return true;
}
function prime(x,y){
for (var j=x; j<y;j++)
if(isprime(j)){
console.log(j)
}
}
prime(3,15)
執行結果
KentdeAir:02 kenttsai$ deno run hw2p.js
3
5
7
11
13
檔案一 : star.js
function star(n)
{
var stars = []
for (var i = 0; i != n; ++i)
{
stars.push("*");
}
console.log(stars);
}
star(7);
執行結果 :
[
"*", "*", "*",
"*", "*", "*",
"*"
]
檔案二 : between.js
function between(a, b)
{
var numbers = [];
for (var i = a; i != b; ++i)
{
numbers.push(i);
}
console.log(numbers);
}
between(9, 29);
執行結果 :
[
9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28
]
加分題檔案三 : primebetween.js
function isPrime(n)
{
for (var i = 2; i < n ** 0.5; ++i)
{
if (n % i == 0)
{
return 0;
}
}
return 1;
}
function primebetween(a, b)
{
var primes = [];
for (var i = a; i != b; ++i)
{
if (isPrime(i))
primes.push(i);
}
console.log(primes);
}
primebetween(7, 67);
執行結果 :
[
7, 9, 11, 13, 17, 19, 23,
25, 29, 31, 37, 41, 43, 47,
49, 53, 59, 61
]
var p=new Array(100039)
var v=new Array(0)
function miku(n){
for(var i=2;i<n;++i){
if(p[i]==1)v.push(i);
for(j of v){
if(i*j>n)break
p[i*j]=0
if(i%j==0)break
}
}
}
p[0]=p[1]=0;
for(var i=2;i<100039;++i)p[i]=1;
miku(100000)
var l=3,r=15
for(var i=l;i<=r;++i){
if(p[i]==1)console.log(i)
}
執行結果
3
5
7
11
13
楊堤筑 資工一 110910527
https://github.com/YangTiChu/wp109b/tree/main/Homework/20210416
110810527 張芷榕 作業1 檔案: star.js
function star(n){
for(var i=0;i<n;i++)
console.log('*')
}
star(5)
輸出結果:
*
*
*
*
*
作業2 檔案: between.js
function between(a,b){
for(var i=a;i<=b;i++){
console.log(i)
}
}
between(3,8)
輸出結果:
3
4
5
6
7
8
加分題 檔案: primebetween.js
function isPrime(n){
if(n==1){
return 1;
}else{
for(var i=2;i<n;i++){
if(n%i==0)
return 0;
}
}
return 1;
}
function primeBetween(a,b){
for(var i=a;i<=b;i++){
if(isPrime(i)){
console.log(i);
}
}
}
primeBetween(3,15)
輸出結果:
3
5
7
11
13
翁志彤 https://github.com/WengChihTung/wp109b/tree/main/homework/02
star(5)
*
*
*
*
*
3
4
5
6
7
8
加分題
3 請寫一個函數 primeBetween(a,b) 可以印出 a..b 之間的質數
例如 primeBetween(3,15)
3
5
7
11
13
記得善用函數,先寫一個判斷是否為質數的函數 isPrime(n) 去判斷會比較好
檔案:star5.js
function star(x) {
for (var i=1;i<=x;i++)
console.log("*")
}
star(5)
執行結果
wengchihtung@MacBook-Pro 02 % deno run star5.js
*
*
*
*
*
檔案:between.js
function between(x,y) {
for (var i=x; i<=y; i++)
console.log(i)
}
between(3,8)
執行結果:
wengchihtung@MacBook-Pro 02 % deno run between.js
3
4
5
6
7
8
檔案:pB.js
function isPrime(n) {
if (n < 2)
return 0;
for (var k=2; k * k <= n; k++)
if (n % k == 0)
return 0;
return 1;
}
function primeBetween(a, b) {
for (var i=a; i<=b; i++)
if (isPrime(i))
console.log(i);
}
primeBetween(3, 15)
執行結果:
wengchihtung@MacBook-Pro 02 % deno run pB.js
3
5
7
11
13
function star(n){ for(var i=0;i<n;++i)console.log("*") } function between(a,r){ for(var i=a;i<=r;++i)console.log(i) } star(5) between(3,8)
執行解果 * 3 4 5 6 7 8
function star(n){ for(var i=0;i<n;++i)console.log("*") } function between(a,r){ for(var i=a;i<=r;++i)console.log(i) } star(5) between(3,8)
執行解果 3 4 5 6 7 8 加分題 function isPrime(n) { if (n < 2) return 0; for (var k=2; k k <= n; k++) if (n % k == 0) return 0; return 1; }
function primeBetween(a, b) { for (var i=a; i<=b; i++) if (isPrime(i)) console.log(i); }
primeBetween(3, 15) 執行 PS C:\Users\spch0.vscode\wp109b\homework\02> deno run plas.js 3 5 7 11 13
資工一 張貽婷 110910526 https://github.com/YiTing1110/wp109b/blob/main/week8/README.md
資工一 吳俊億 110910528 https://github.com/kaifeng273/wp109b/blob/main/homework2/homework2.md
資工一 羅彥翔 110910519 https://github.com/Roy-Roo/wp109b/blob/main/week8/HW2/README.md
資工一 110910518 黃紹安 檔案:JS homework.js
for(var i=0;i<n;++i)console.log("*")
}
function between(a,r){
for(var i=a;i<=r;++i)console.log(i)
}
star(6)
between(3,12)
執行結果
PS C:\Users\shaoan901226\wp109b\week8\JS homework.js> deno run plas.js
*
*
*
*
*
*
3
4
5
6
7
8
9
10
11
12
資工二 110710336 李思慧 https://github.com/4YCAaaa/wp109b/tree/main/JSExercise_Hw
資工一 110910533 曾旭宏 homework.js 作業一:
function star(a) {
for(var i=0;i<a;i++) console.log("*")
}
star(5)
結果:
*
*
*
*
*
作業二:
function between(a,b) {
for(;a<=b;a++) console.log(a)
}
between(3,8)
結果:
3
4
5
6
7
8
加分題:
function primeBetween(a,b) {
var t=0
for(;a<=b;a++)
{
t=0
for(var i=2;i<=a/2;i++)
{
if(a%i==0)
{
t=1
break
}
}
if(t==0 && a>1) console.log(a)
}
}
primeBetween(3,15)
結果:
3
5
7
11
13
資工一110910506林庭光 https://github.com/Lin610313/wp109b/tree/main/week8/homework2
資工一 姜呈諭 110910531 檔案 hw2.js
function star(n) {
for (var i=0; i<n; i++)
console.log('*')
}
function between(x,y){
for (var i=x; i<=y; i++ )
console.log(i)
}
star(5)
between(3,8)
執行結果
*
*
*
*
*
3
4
5
6
7
8
資工一 魏仲彥 110910541 homework*3 程式原始檔
資工一 徐伯元 110910542 https://github.com/z22756392z/wp109b/tree/main/js
110910513 林孫全
檔案 home_work2.js
function stars(n) {
for (var i=0; i<n; i++)
console.log('*')
}
function between(x,y){
for (var i=x; i<=y; i++ )
console.log(i)
}
stars(5)
between(3,8)
執行結果
todd02 todd$ deno run home_work2.js * 3 4 5 6 7 8 檔案 hw2p.js
function isprime(n){
for (var i=2; i<n;i++){
if(n%i==0){
return false;
}
};
return true;
}
function prime(x,y){
for (var j=x; j<y;j++)
if(isprime(j)){
console.log(j)
}
}
prime(3,15)
執行結果
todd02 todd$ deno run hw2p.js 3 5 7 11 13
110910530 黃劭騏
function star(n) {
for (var i=0; i<n; i++)
console.log('*')
}
function between(x,y){
for (var i=x; i<=y; i++ )
console.log(i)
}
star(5)
between(3,8)
執行結果
KentdeAir:02 kenttsai$ deno run hw2.js
*
*
*
*
*
3
4
5
6
7
8
110612321 黃偉齊
/**
* Print n Stars.
* @param {number} n
*/
function star(n) {
while (n--) {
console.log('*');
}
}
/**
* Print integer between min to max.
* @param {number} min
* @param {number} max
*/
function between(min, max) {
for (let i = min; i <= max; i++) {
console.log(i);
}
}
/**
* Check if n is an prime.
* @param {number} n
* @return {boolean}
*/
function isPrime(n) {
if (n < 2) {
return false;
}
for (let i = 2; i <= n / 2; i++) {
if (n % i === 0) {
return false;
}
}
return true;
}
/**
* Print prime between a to b.
* @param {number} a must < b
* @param {number} b
*/
function primeBetween(a, b) {
for (let i = a; i <= b; i++) {
if (isPrime(i)) {
console.log(i);
}
}
}
110910534 李翊慈 https://github.com/cabdy1735/wp109b/tree/main/week8
110910510吳昆儒 檔案 hw2.js
function star(n){
for(var i=0;i<n;++i)console.log("*")
}
star(5)
執行結果
*
*
*
*
*
檔案 hw2().js
function between(x,y){
for (var i=x; i<=y; i++ )
console.log(i)
}
between(3,8)
執行結果
3
4
5
6
7
8
檔案 hw2<>.js
function isprime(n){
for (var i=2; i<n;i++){
if(n%i==0){
return false;
}
};
return true;
}
function prime(x,y){
for (var j=x; j<y;j++)
if(isprime(j)){
console.log(j)
}
}
prime(2,9)
執行結果
2
3
5
7
110910522 劉煒辰 https://github.com/Paouser/wp109b/tree/main/homework/02
檔案:star.js
function star(n) { for (var i=0; i<n ; i++) console.log('*') }
star (5)
執行結果 *
第二題 檔案:between.js
function between (a,b){ for (var i=0;i<=b;i++) if (i>=a) console.log(i);
}
between(2,9)
執行結果
2 3 4 5 6 7 8 9
第三題
檔案:isPrime.js
function between(a,b){ for (var i=0;i<=b;i++) if (i>=a) isPrime(i); }
function isPrime(a){ var b=0; for(var i=1;i<a;i++) if (a%i==0)b++ if (b==1)console.log(a) }
between(2,11)
執行結果
2 3 5 7 11
110910515 陳文吉 第一題 檔案:star.js
function star(n) {
for (var i=0;i<n;i++)
console.log('*')
}
star(5)
執行結果 PS D:\網頁設計\wp109b\homework\hw02> deno run star.js *
第二題 檔案:between.js
function between(a,b){
for(var i=a;i<=b;++i)
console.log(i)
}
between(3,8)
執行結果:
PS D:\網頁設計\wp109b\homework\hw02> deno run between.js
3
4
5
6
7
8
加分題 檔案:bonus.js
function between(a,b){
for(var n=a;n<b;n++)
if (isPrime(n)){
console.log(n)
}
}
function isPrime(n){
if(n<2)
{
return false
}
for (var z=2;z<n;z++)
{
if(n%z==0){
return false
}
return true
}
}
between(3,15)
執行結果 PS D:\網頁設計\wp109b\homework\hw02> deno run bonus.js 3 5 7 9 11 13
110713334 林鋐彰 檔案:hw2.js function st(n) { for(var i=0;i<n;++i)console.log("*") } function between(a,r){ for(var i=a;i<=r;++i)console.log(i) } star(7) between(5,13) 執行結果
PS C:\Users\kmmc2490173\wp109b\week8\ hw2.js> deno run hw2.js * 5 6 7 8 9 10 11 12 13
function star(n)
{
var stars = []
for (var i = 0; i != n; ++i)
{
stars.push("*");
}
console.log(stars);
}
star(7);
[ "", "", "", "", "", "", "*" ]
function between(a, b)
{
var numbers = [];
for (var i = a; i != b; ++i)
{
numbers.push(i);
}
console.log(numbers);
}
between(9, 29);
[ 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28 ]
function isPrime(n)
{
for (var i = 2; i < n ** 0.5; ++i)
{
if (n % i == 0)
{
return 0;
}
}
return 1;
}
function primebetween(a, b)
{
var primes = [];
for (var i = a; i != b; ++i)
{
if (isPrime(i))
primes.push(i);
}
console.log(primes);
}
primebetween(7, 29);
[ 3, 5, 7, 11, 13, 17, 19, 23 ,29 ]
110910536 邱麟翔 作業https://github.com/QuiLinxinag/wp109b/tree/main/homework
工管一 110911542 邵南翔
1st star
function star(n)
{
for(var i=0; i<=n; i++)
{
console.log("*");
}
}
star(5);
OutPut
*
*
*
*
*
2nd between
function between(a,b)
{
for(var a; a<=b; a++)
{
console.log(a);
}
}
between(3,8);
OutPut
3
4
5
6
7
8
3rd prime between
function isPrime(n){
if(n<2) return 0
for(var x=2;x*x<=n;++x) if(n%x == 0) return 0
return 1
}
function between(a,b)
{
for(var i=a;i<=b;++i) if(isPrime(i))
console.log(i)
}
between(15,30)
OutPut
17
19
23
29
資工一 110910544 張博翔 程式一
function star(n)
{
for(var i=0; i<=n; i++)
{
console.log("*");
}
}
star(5);
output
*
*
*
*
*
function between(a,b)
{
for(var a; a<=b; a++)
{
console.log(a);
}
}
between(3,8);
output
3
4
5
6
7
8
function isPrime(n){
if(n<2) return 0
for(var x=2;x*x<=n;++x) if(n%x == 0) return 0
return 1
}
function between(a,b)
{
for(var i=a;i<=b;++i) if(isPrime(i))
console.log(i)
}
between(15,30)
output
17
19
23
29
例如: star(5) 會印出 5 個 * 號
star(5)
例如: between(3,8) 會印出
加分題
3 請寫一個函數 primeBetween(a,b) 可以印出 a..b 之間的質數
例如 primeBetween(3,15)
記得善用函數,先寫一個判斷是否為質數的函數 isPrime(n) 去判斷會比較好