-
Notifications
You must be signed in to change notification settings - Fork 0
/
stolarsky array.c
77 lines (51 loc) · 944 Bytes
/
stolarsky array.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<stdio.h>>
int main(){
int i,j,k,n,m,mark=0,t;
printf("enter the size of stolarsky array you want\n");
scanf("%d %d",&n,&m);
int a[n][m];
a[0][0]=1,a[0][1]=2;
for(i=0;i<n;i++){
if(i>0){
for(t=1;;t++){
mark=0;
for(j=0;j<i;j++){
for(k=0;k<m;k++){
if(a[j][k]==t){
mark=1;
break;}
}
if(mark==1){
break;}
}
if(mark==0){
a[i][0]=t;
break;}
}
for(t=a[i][0]+1;;t++){
mark=0;
for(j=0;j<i;j++){
for(k=0;k<m;k++){
if(a[j][k]==t){
mark=1;
break;}
}
if(mark==1){
break;}
}
if(mark==0){
a[i][1]=t;
break;}
}
}
for(j=2;j<m;j++){
a[i][j]=a[i][j-1]+a[i][j-2];
}
}
for(i=0;i<n;i++){
for(j=0;j<m;j++){
printf("%d ",a[i][j]);
}
printf("\n");
}
}