質問<729>2001/12/9
from=まっちゃん
「プログラミング」


次を basicでプログラムしたいのですが 解りません。
教えて下さい。
(1)n個のa(0),a(1),・・・・,a(n-1)が与えられてい
   る?? a(i)の順位rを求める。
(2)n次正??行列A,Bが与えられた?? この2つの行列の
   和と差と積を求める。


お返事2001/12/18
from=武田


問1
10 n=10:cls                            :'データ数
20 dim a(n),b(n)
30 data 2,4,3,8,5,4,6,7,3,1            :'データの数値(10個)
40 for k=1 to n
50 read a(k)
60 next k
70 for t=1 to n
80 count=0
90 for s=1 to n
100 if a(t)<a(s) then count=count+1
110 next s
120 b(t)=count+1
130 next t
170 for k=1 to n
180 print k;"番目の得点";a(k);"は";n;"人中";b(k);"位です。"
190 next k
200 end

問2
A=(aij)、B=(bij)、C=(cij)とすると、
和(差)は、
A+B=C

100 n=3:cls
110 dim a(n,n),b(n,n),c(n,n)
120 '-------A------
130 data 2,4,3
140 data -8,5,-4
150 data 6,7,3
160 '-------B------
170 data 1,-2,9
180 data 0,2,4
190 data -1,6,5
200 '--------------
210 for i=1 to n
220 for j=1 to n
230 read a(i,j)
240 next j
250 next i
260 '---------------
270 for i=1 to n
280 for j=1 to n
290 read b(i,j)
300 next j
310 next i
320 '---------------
330 for i=1 to n
340   for j=1 to n
350     c(i,j)=a(i,j)+b(i,j)            :'和
360   next j
370 next i
380 '---------------
390 print "A="
400 print
410 for i=1 to n
420 print "(",
430 for j=1 to n
440 print a(i,j),
450 next j
460 print ")"
470 next i
480 print
490 '-----------------
500 print "B="
510 print
520 for i=1 to n
530 print "(",
540 for j=1 to n
550 print b(i,j),
560 next j
570 print ")"
580 next i
590 print
600 '-----------------
610 print "C=A+B="
620 print
630 for i=1 to n
640 print "(",
650 for j=1 to n
660 print c(i,j),
670 next j
680 print ")"
690 next i
700 print
710 end

A=(aij)、B=(bij)、C=(cij)とすると、
積は、
A・B=C

100 n=3:cls
110 dim a(n,n),b(n,n),c(n,n)
120 '-------A------
130 data 2,4,3
140 data -8,5,-4
150 data 6,7,3
160 '-------B------
170 data 1,-2,9
180 data 0,2,4
190 data -1,6,5
200 '--------------
210 for i=1 to n
220 for j=1 to n
230 read a(i,j)
240 next j
250 next i260 '---------------
270 for i=1 to n
280 for j=1 to n
290 read b(i,j)300 next j
310 next i
320 '---------------
330 for i=1 to n
340 for j=1 to n
350 c(i,j)=0
360 next j
370 next i
380 for i=1 to n
390   for j=1 to n
400     for k=1 to n
410       c(i,j)=c(i,j)+a(i,k)*b(k,j)            :'積
420     next k
430   next j
440 next i
450 '---------------
460 print "A="
470 print
480 for i=1 to n
490 print "(",
500 for j=1 to n
510 print a(i,j),
520 next j
530 print ")"
540 next i
550 print
560 '-----------------
570 print "B="
580 print
590 for i=1 to n
600 print "(",
610 for j=1 to n
620 print b(i,j),
630 next j
640 print ")"
650 next i
660 print
670 '-----------------
680 print "C=A×B="
690 print
700 for i=1 to n
710 print "(",
720 for j=1 to n
730 print c(i,j),
740 next j
750 print ")"
760 next i
770 print
780 end