解答例
解答例

(類題1)

(1) PRINT "Student"

(2) PRINT "札幌市"

(3) PRINT "プログラム"



(類題2)

(1) PRINT 12/3*56

(2) PRINT 1+2*3/4−5

(3) PRINT (3.14*2-4)/(4*25)



(類題3)

(1) PRINT SQR(7)/SQR(11)

(2) PRINT ABS(-4.3)

(3) PRINT INT(4*2.3)



(類題4)

(1) x=−2:y=4:PRINT x+2*y

(2) x=3.4:PRINT (2*x-SQR(3*X))/3

(3) a=−5:b=3:PRINT a*(a+2*b) 

(4) a=5:b=4:PRINT a^4-3*b^2 



(類題5)

1: pi=3.14

2: r=3

3: V=4/3*pi*r^3

4: PRINT "V=";V



(類題6-1)

1: INPUT "r=";r

2: INPUT "a=";a

3: pi=3.14159

4: S=pi*r^2*a/180

5: PRINT "S=";S



(類題6-2)

1: INPUT "a=";a

2: PRINT "S=";6*a^2



(類題7)

(1)

1: INPUT "x=";x

2: PRINT INT(10*x)/10

(2) 

1: INPUT "x=";x

2: PRINT INT(10*x+0.5)/10

(3)

1: INPUT "x=";x

2: PRINT INT(10*x+1)/10



(類題8-1)

1: INPUT "m=";m

2: INPUT "n=";n

3: sum=0

4: FOR i=m TO n

5:      sum=sum+i^2

6: NEXT i

7: PRINT "S=";sum



(類題8-2)

1: INPUT "n=";n

1: sum=1                '初期値1

2: FOR i=r TO n

3:    sum=sum*i            '積の取得

4: NEXT i

5: PRINT "S=";sum



(類題8-3)

1: INPUT "n=";n

2: INPUT "r=";r

3: sum=1

4: FOR i=n-r+1 TO n

5:      sum=sum*i

6: NEXT i

7:  PRINT "S=";sum



(類題9-1)

1:  sum=0               '初期値0

2:  FOR i=n TO 1000 STEP n        'step n でnの倍数

3:    sum=sum+i           '和の取得

4:  NEXT i

5:  PRINT "和=";sum



(類題9-2)

1: FOR x=0 TO 1 STEP 0.1

2:      y=2*x^2-3*x-1

3:      PRINT y

4: NEXT x



(類題9-3)

1: pi=3.14159

2: FOR x=0 TO 90 STEP 10

3:      y=SIN(pi*x/180)

4:      PRINT x,y

5: NEXT x



(類題10)

1: sum=0

2: FOR i=1 TO 30

3:      a=1 

4:      FOR j=1 TO 30 

5:          a=a+2*(j-1)+1

6:      NEXT j

7:      sum=sum+a

8: NEXT i

9: PRINT "S=";sum



(類題11-1)

1: INPUT "a=";a

2: INPUT "b=";b

3: INPUT "c=";c

4: INPUT "d=";d

5: min=a				    '仮の最小値をaに

6: IF b>min THEN min=b      'b,minの小さい方をminに

7: IF c>>min THEN min=c       'c,minの小さい方をminに

8: IF d>>min THEN min=d       'd,minの小さい方をminに

9: PRINT min              'minの値が最小値



(類題11-2)

1: FOR n=1 TO 1000

2:      IF n^2>1000 THEN 

3:          PRINT n^2

4:          END

5:      END IF

6: NEXT i



(類題12)

(LIST)

1: INPUT "a=";a

2: INPUT "b=";b

3: SELECT CASE a            '値aによる分岐

5: CASE IS =0               'a=0のとき

6:      SELECT CASE b                           '値bによる分岐

7:       CASE IS =0				'b=0のとき

8:  	    PRINT "すべての実数"

9:       CASE IS <>0				'b<>0のとき

10:            PRINT "解なし"

11:       END SELECT

12: CASE IS <>0				'a<>0のとき

13: 	PRINT "x=";b/a

14: END SELECT



(類題13)

1: sum=0

2: DO

3:      INPUT "x=";x)

4:      IF x>0 THEN sum=sum+x^2 ELSE PRINT "S=";sum:END 

5: LOOP



(類題14-1)

1:  DIM a(1 TO 10)              '10個の値の配列

2:  sum=0

3:  FOR i=1 TO 10

4:    INPUT "値を入力してください。";a(i)

5:    sum=sum+a(i)^2               '平方の和の取得

6:  NEXT i

7:  m=sum/10                   '平均 m=合計点/個数

8:  FOR i=1 to 10

9:    PRINT a(i)^2-m

10:  NEXT i



(類題14-2)

1: DIM a(1 TO 10)            '10個分の値の配列

2: FOR i=1 to 10

3:       INPUT "値を入力してください";a(i)	'値の入力

4: NEXT i

5: max=0				'最大値の初期化

6: FOR i=1 TO 10

7:    IF a(i)>max THEN max=a(i)

8: NEXT i

9: PRINT "最大値は";a(i)



(類題15)

1: DIM a(1 TO 10)

2: FOR i=1 TO 10

3:      INPUT a(i)

4: NEXT i

5: FOR i=1 TO 9

6:      FOR j=1 TO 10-i

7:          IF a(j)<a(j+1) THEN

8:              l=a(j+1)

9:              a(j+1)=a(j)

10:              a(j)=l

11:          END IF

12:      NEXT j

13: NEXT i

14: FOR i=1 TO 10

15:      PRINT a(i);

16: NEXT i



(類題16)

1: DIM p(1 TO 200)

2: FOR m=2 TO 200

3:      FOR n=m*2 TO 200 STEP m

4:          p(n)=1

5:      NEXT n

6: NEXT m

7: p(1)=1

8: FOR n=1 TO 200

9:      IF p(n)=1 THEN PRINT "..."; ELSE PRINT n;

10:      IF n MOD 10=0 THEN PRINT

11: NEXT n



(類題17)

1: INPUT "n=";n

2: FOR k=1 TO n

3:      r=n-k*INT(n/k)

4:      IF r=0 THEN PRINT k

5: NEXT k



(類題18)

(1)

1:  DIM a(10)

2:  a(1)=1

3:  FOR n=1 TO 19

4:    a(n+1)=3*a(n)+2

5:  NEXT n

6:  FOR n=1 TO 20

7:    PRINT a(n)

8:  NEXT n

(2)

1:  DIM a(20)

2:  a(1)=1:a(2)=2

3:  FOR n=1 TO 18

4:    a(n+2)=2*a(n+1)-a(n)

5:  NEXT n

6:  FOR n=1 TO 20

7:    PRINT a(n)

8:  NEXT n

(3)

1:  DIM a(10)

2:  a(1)=1

3:  FOR n=1 TO 19

4:    a(n+1)=a(n)+3*2^(n-1)

5:  NEXT n

6:  FOR n=1 TO 20

7:    PRINT a(n)

8:  NEXT n



(類題19)

(1)

1:  s=0

2:  FOR k=1 TO 15

3:    s=s+(3*k-2)

4:  NEXT k

5:  PRINT s

(2)

1:  s=0

2:  FOR n=1 TO 15

3:    s=s+n*(n+1)/2

4:  NEXT n

5:  PRINT s



(類題20)

1:  INPUT "a,b";a,b

2:  INPUT "p,q,n";p,q,n

3:  d=(q-p)/n

4:  FOR x=p TO q STEP d

5:    y=a*x+b

6:    PRINT "f(";x;")";y

7:  NEXT x



(類題21)

1:  x=2

2:  i=0.1

3:  DO WHILE i>=0.0001

4:    DO WHILE y<=0

5:      x=x+i

6:      y=x^2-2*x-1

7:    LOOP

8:    x=x-i

9:    i=i*0.1

10:  LOOP

11:  z=INT(1000*x+0.5)/1000

12:  PRINT z