Jump to content

Multiplication tables: Difference between revisions

(FALSE)
Line 840:
 
mult.table 12
</lang>
 
=={{header|MATLAB}}==
 
timestable.m (creates Times Table of N degree)
<lang>
function M=timestable(N)
A=zeros(N+1,N+1);
B=zeros(N+1,N+1);
C=zeros(N+1,N+1);
for i=1:N
A(i+1,1)=i;
for j=1:N
A(1,j+1)=j;
B(i+1,j+1)=i*j;
end
end
i=1;
for j=1:N
C(i,j)=1;
end
j=1;
for i=1:N+1
C(i,j)=1;
end
for i=2:N+1
for j=2:N+1
if i<=j
C(i,j)=1;
end
end
end
M=A+(B.*C);
</lang>
 
for N=12
<lang>
>>timestable(12)
 
ans =
 
0 1 2 3 4 5 6 7 8 9 10 11 12
1 1 2 3 4 5 6 7 8 9 10 11 12
2 0 4 6 8 10 12 14 16 18 20 22 24
3 0 0 9 12 15 18 21 24 27 30 33 36
4 0 0 0 16 20 24 28 32 36 40 44 48
5 0 0 0 0 25 30 35 40 45 50 55 60
6 0 0 0 0 0 36 42 48 54 60 66 72
7 0 0 0 0 0 0 49 56 63 70 77 84
8 0 0 0 0 0 0 0 64 72 80 88 96
9 0 0 0 0 0 0 0 0 81 90 99 108
10 0 0 0 0 0 0 0 0 0 100 110 120
11 0 0 0 0 0 0 0 0 0 0 121 132
12 0 0 0 0 0 0 0 0 0 0 0 144
</lang>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.