关于fortran语言的数组定义问题1
发布网友
发布时间:2023-10-23 16:54
我来回答
共3个回答
热心网友
时间:2024-11-29 09:47
float IPRM(1:12),float soillocat(94896,2),int lcov(3)
这上面的是C吧,fortran没有这些关键词,除非自定义了关键词。
REAL A(10,3,2),这个才是fortran,real就是float形。float a[10,3,2],
int对应fortran里面的integer形。
区别差不多就在于圆括号何方括号吧。
热心网友
时间:2024-11-29 09:47
这是10年前我用QBASIC编写的一个程序,元素分别用A,B,C,D,……表示,不再改了。QBASIC是很容易找到的一个小程序,在90年代中期使用的人还是不少的。程序编得并不好,但毕竟是我刚刚拥有自己的电脑时编着玩的。这个程序可以打印从n(运行时自己输入)个不同元素中取k(运行时自己输入,当时编写的时候*k不超过10)个不同元素的全部组合。
下面是程序运行的结果:
ABC, ABD, ABE, ABF, ABG,
ABH, ABI, ABJ, ACD, ACE,
ACF, ACG, ACH, ACI, ACJ,
ADE, ADF, ADG, ADH, ADI,
ADJ, AEF, AEG, AEH, AEI,
AEJ, AFG, AFH, AFI, AFJ,
AGH, AGI, AGJ, AHI, AHJ,
AIJ, BCD, BCE, BCF, BCG,
BCH, BCI, BCJ, BDE, BDF,
BDG, BDH, BDI, BDJ, BEF,
BEG, BEH, BEI, BEJ, BFG,
BFH, BFI, BFJ, BGH, BGI,
BGJ, BHI, BHJ, BIJ, CDE,
CDF, CDG, CDH, CDI, CDJ,
CEF, CEG, CEH, CEI, CEJ,
CFG, CFH, CFI, CFJ, CGH,
CGI, CGJ, CHI, CHJ, CIJ,
DEF, DEG, DEH, DEI, DEJ,
DFG, DFH, DFI, DFJ, DGH,
DGI, DGJ, DHI, DHJ, DIJ,
EFG, EFH, EFI, EFJ, EGH,
EGI, EGJ, EHI, EHJ, EIJ,
FGH, FGI, FGJ, FHI, FHJ,
FIJ, GHI, GHJ, GIJ, HIJ,
共有 120 种
下面是程序:
CLS
100 PRINT " 本程序用于打印从n个元素中任取k个元素的全部组合"
INPUT " n="; n
IF n = 0 THEN END
DIM a$(n)
FOR i = 1 TO n
a$(i) = CHR$(i + 64)
NEXT i
w = 0
INPUT "输入不超过 10 的整数 k="; k
IF k = 1 THEN GOSUB 1
IF k = 2 THEN GOSUB 2
IF k = 3 THEN GOSUB 3
IF k = 4 THEN GOSUB 4
IF k = 5 THEN GOSUB 5
IF k = 6 THEN GOSUB 6
IF k = 7 THEN GOSUB 7
IF k = 8 THEN GOSUB 8
IF k = 9 THEN GOSUB 9
IF k = 10 THEN GOSUB 10
PRINT
IF w = 0 THEN 20
PRINT "共有"; w; "种"
END
20 PRINT "共有 1 种"
END
1 FOR i = 1 TO n - k + 1
PRINT a$(i),
w = w + 1
NEXT i
RETURN
2 FOR i = 1 TO n - k + 1
FOR i1 = 1 TO n - k + 2 - i
PRINT a$(i); a$(i + i1),
w = w + 1
NEXT i1
NEXT i
RETURN
3 FOR i = 1 TO n - k + 1
FOR i1 = 1 TO n - k + 2 - i
FOR i2 = 1 TO n - k + 3 - i - i1
PRINT a$(i); a$(i + i1); a$(i + i1 + i2),
w = w + 1
NEXT i2
NEXT i1
NEXT i
RETURN
4 FOR i = 1 TO n - k + 1
FOR i1 = 1 TO n - k + 2 - i
FOR i2 = 1 TO n - k + 3 - i - i1
FOR i3 = 1 TO n - k + 4 - i - i1 - i2
PRINT a$(i); a$(i + i1); a$(i + i1 + i2); a$(i + i1 + i2 + i3),
w = w + 1
NEXT i3
NEXT i2
NEXT i1
NEXT i
RETURN
5 FOR i = 1 TO n - k + 1
FOR i1 = 1 TO n - k + 2 - i
FOR i2 = 1 TO n - k + 3 - i - i1
FOR i3 = 1 TO n - k + 4 - i - i1 - i2
FOR i4 = 1 TO n - k + 5 - i - i1 - i2 - i3
PRINT a$(i); a$(i + i1); a$(i + i1 + i2); a$(i + i1 + i2 + i3); a$(i + i1 + i2 + i3 + i4),
w = w + 1
NEXT i4
NEXT i3
NEXT i2
NEXT i1
NEXT i
RETURN
6 FOR i = 1 TO n - k + 1
FOR i1 = 1 TO n - k + 2 - i
FOR i2 = 1 TO n - k + 3 - i - i1
FOR i3 = 1 TO n - k + 4 - i - i1 - i2
FOR i4 = 1 TO n - k + 5 - i - i1 - i2 - i3
FOR i5 = 1 TO n - k + 6 - i - i1 - i2 - i3 - i4
PRINT a$(i); a$(i + i1); a$(i + i1 + i2); a$(i + i1 + i2 + i3); a$(i + i1 + i2 + i3 + i4); a$(i + i1 + i2 + i3 + i4 + i5),
w = w + 1
NEXT i5
NEXT i4
NEXT i3
NEXT i2
NEXT i1
NEXT i
RETURN
7 FOR i = 1 TO n - k + 1
FOR i1 = 1 TO n - k + 2 - i
FOR i2 = 1 TO n - k + 3 - i - i1
FOR i3 = 1 TO n - k + 4 - i - i1 - i2
FOR i4 = 1 TO n - k + 5 - i - i1 - i2 - i3
FOR i5 = 1 TO n - k + 6 - i - i1 - i2 - i3 - i4
FOR i6 = 1 TO n - k + 7 - i - i1 - i2 - i3 - i4 - i5
PRINT a$(i); a$(i + i1); a$(i + i1 + i2); a$(i + i1 + i2 + i3); a$(i + i1 + i2 + i3 + i4); a$(i + i1 + i2 + i3 + i4 + i5); a$(i + i1 + i2 + i3 + i4 + i5 + i6),
w = w + 1
NEXT i6
NEXT i5
NEXT i4
NEXT i3
NEXT i2
NEXT i1
NEXT i
RETURN
8 FOR i = 1 TO n - k + 1
FOR i1 = 1 TO n - k + 2 - i
FOR i2 = 1 TO n - k + 3 - i - i1
FOR i3 = 1 TO n - k + 4 - i - i1 - i2
FOR i4 = 1 TO n - k + 5 - i - i1 - i2 - i3
FOR i5 = 1 TO n - k + 6 - i - i1 - i2 - i3 - i4
FOR i6 = 1 TO n - k + 7 - i - i1 - i2 - i3 - i4 - i5
FOR i7 = 1 TO n - k + 8 - i - i1 - i2 - i3 - i4 - i5 - i6
PRINT a$(i); a$(i + i1); a$(i + i1 + i2); a$(i + i1 + i2 + i3); a$(i + i1 + i2 + i3 + i4); a$(i + i1 + i2 + i3 + i4 + i5); a$(i + i1 + i2 + i3 + i4 + i5 + i6); a$(i + i1 + i2 + i3 + i4 + i5 + i6 + i7),
w = w + 1
NEXT i7
NEXT i6
NEXT i5
NEXT i4
NEXT i3
NEXT i2
NEXT i1
NEXT i
RETURN
9 FOR i = 1 TO n - k + 1
FOR i1 = 1 TO n - k + 2 - i
FOR i2 = 1 TO n - k + 3 - i - i1
FOR i3 = 1 TO n - k + 4 - i - i1 - i2
FOR i4 = 1 TO n - k + 5 - i - i1 - i2 - i3
FOR i5 = 1 TO n - k + 6 - i - i1 - i2 - i3 - i4
FOR i6 = 1 TO n - k + 7 - i - i1 - i2 - i3 - i4 - i5
FOR i7 = 1 TO n - k + 8 - i - i1 - i2 - i3 - i4 - i5 - i6
FOR i8 = 1 TO n - k + 9 - i - i1 - i2 - i3 - i4 - i5 - i6 - i7
PRINT a$(i); a$(i + i1); a$(i + i1 + i2); a$(i + i1 + i2 + i3); a$(i + i1 + i2 + i3 + i4); a$(i + i1 + i2 + i3 + i4 + i5); a$(i + i1 + i2 + i3 + i4 + i5 + i6); a$(i + i1 + i2 + i3 + i4 + i5 + i6 + i7); a$(i + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8),
w = w + 1
NEXT i8
NEXT i7
NEXT i6
NEXT i5
NEXT i4
NEXT i3
NEXT i2
NEXT i1
NEXT i
RETURN
10 FOR i = 1 TO n - k + 1
FOR i1 = 1 TO n - k + 2 - i
FOR i2 = 1 TO n - k + 3 - i - i1
FOR i3 = 1 TO n - k + 4 - i - i1 - i2
FOR i4 = 1 TO n - k + 5 - i - i1 - i2 - i3
FOR i5 = 1 TO n - k + 6 - i - i1 - i2 - i3 - i4
FOR i6 = 1 TO n - k + 7 - i - i1 - i2 - i3 - i4 - i5
FOR i7 = 1 TO n - k + 8 - i - i1 - i2 - i3 - i4 - i5 - i6
FOR i8 = 1 TO n - k + 9 - i - i1 - i2 - i3 - i4 - i5 - i6 - i7
FOR i9 = 1 TO n - k + 10 - i - i1 - i2 - i3 - i4 - i5 - i6 - i7 - i8
PRINT a$(i); a$(i + i1); a$(i + i1 + i2); a$(i + i1 + i2 + i3); a$(i + i1 + i2 + i3 + i4); a$(i + i1 + i2 + i3 + i4 + i5); a$(i + i1 + i2 + i3 + i4 + i5 + i6); a$(i + i1 + i2 + i3 + i4 + i5 + i6 + i7); a$(i + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8); a$(i + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9),
w = w + 1
NEXT i9
NEXT i8
NEXT i7
NEXT i6
NEXT i5
NEXT i4
NEXT i3
NEXT i2
NEXT i1
NEXT i
RETURN
热心网友
时间:2024-11-29 09:48
C语言的数组概念的学习,通过for循环输出打印数组