Print this Multiplication Table

19

2

Write shortest code to print the following Multiplication Table:

1×1=1
1×2=2  2×2=4
1×3=3  2×3=6  3×3=9
1×4=4  2×4=8  3×4=12 4×4=16
1×5=5  2×5=10 3×5=15 4×5=20 5×5=25
1×6=6  2×6=12 3×6=18 4×6=24 5×6=30 6×6=36
1×7=7  2×7=14 3×7=21 4×7=28 5×7=35 6×7=42 7×7=49
1×8=8  2×8=16 3×8=24 4×8=32 5×8=40 6×8=48 7×8=56 8×8=64
1×9=9  2×9=18 3×9=27 4×9=36 5×9=45 6×9=54 7×9=63 8×9=72 9×9=81

matrix89

Posted 2013-04-15T10:57:33.093

Reputation: 623

6Is anyone really going to do anything besides 2 for loops? Where's the challenging (interesting) part? – jdstankosky – 2013-04-15T23:56:30.827

3I don't use for. Ok, I use while. – Johannes Kuhn – 2013-04-16T13:31:39.520

3Are trailing spaces important? – Reinstate Monica – 2013-05-13T19:06:29.160

why in the first column there are 2 spaces and not 1? (as the other colums ) – RosLuP – 2016-09-20T15:21:15.910

@jdstankosky My answer uses the inverted upper triangle of a scaled identity matrix :). – Magic Octopus Urn – 2016-09-20T16:15:02.270

1@jdstankosky perhaps you may find my answer a bit more interesting - no loops involved – Taylor Scott – 2017-07-22T21:03:20.893

1Are we even allowed to use x in place of ×? (If not, that invalidates a whole lot of programs) – Zacharý – 2017-07-23T00:33:20.577

@jdstankosky I use a time loop! – sergiol – 2018-04-15T12:31:59.277

Answers

14

Excel, 92 91 Bytes

From the VBA editor's immediate window, run the following command: Range("A1:I9").Formula="=IF(ROW()<COLUMN(),"""",COLUMN()&""×""&ROW()&""=""&COLUMN()*ROW())" The output is directly on the active worksheet. Excel output screenshot

I golfed an extra byte by swapping the order of an if to change >= to <. I didn't update the screenshot, but it only affects the formula at the top, not the output.

GuitarPicker

Posted 2013-04-15T10:57:33.093

Reputation: 1 101

HA! I wondered when I'd see an excel answer, +1. – Magic Octopus Urn – 2016-09-20T15:54:11.280

1Thanks. I think I was partially motivated by the comments about doing it without the usual nested FOR loop. – GuitarPicker – 2016-09-20T18:00:56.230

Mine was too!!! – Magic Octopus Urn – 2016-09-21T20:32:04.553

8

Python (75)

r=range(1,10)
for i in r:print''.join('%sx%s=%-3s'%(j,i,i*j)for j in r[:i])

a little better golfed than the other two Python versions.

Daniel

Posted 2013-04-15T10:57:33.093

Reputation: 1 801

Use Python 3.6 with f-strings for -1 bytes: TIO

– connectyourcharger – 2019-07-04T22:37:00.480

7

C++, 106 98 bytes

I used two loops and a few tricks.

#import <cstdio>
main(){for(int i,j;i++-9;j=0)while(j++-i)printf("%dx%d=%d%c",j,i,i*j,j<i?32:10);}

FoxyZ

Posted 2013-04-15T10:57:33.093

Reputation: 81

Welcome to PPCG! Nice first post! – Rɪᴋᴇʀ – 2016-07-23T20:00:14.440

1#import <stdio.h> main(){for(int i=0,j;i++-9;j=0)while(j++-i)printf("%dx%d=%d%s",j,i,i*j,j<i?"\n":" ";} is 3 bytes shorter. – James – 2016-07-23T20:13:06.493

Do you need a space between #import and <cstdio>? – Zacharý – 2017-07-10T16:50:27.187

@Zacharý no that space is not needed – Karl Napf – 2017-08-07T12:39:15.583

5

J: 57 51 characters

([:;"2*\#"2(":@],'x',":@[,'=',":@*,' '"_)"0/~)>:i.9

No loops.

SL2

Posted 2013-04-15T10:57:33.093

Reputation: 171

Conjunctions (and adverbs) have higher precedence than verbs so you can remove 3 pairs of brackets. ([:;"2*\#"2(":@],'x',":@[,'=',":@*,' '"_)"0/~)>:i.9 – randomra – 2013-04-16T21:06:05.113

@randomra Good call. Thanks for the tip! – SL2 – 2013-04-16T21:12:42.457

4

Ruby: 60 59 characters

1.upto(9){|i|puts (1..i).map{|j|"%dx%d=%-3d"%[j,i,i*j]}*""}

Sample run:

bash-4.2$ ruby -e '1.upto(9){|i|puts (1..i).map{|j|"%dx%d=%-3d"%[j,i,i*j]}*""}'
1x1=1 
1x2=2  2x2=4 
1x3=3  2x3=6  3x3=9 
1x4=4  2x4=8  3x4=12 4x4=16
1x5=5  2x5=10 3x5=15 4x5=20 5x5=25
1x6=6  2x6=12 3x6=18 4x6=24 5x6=30 6x6=36
1x7=7  2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49
1x8=8  2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64
1x9=9  2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81

manatwork

Posted 2013-04-15T10:57:33.093

Reputation: 17 865

Could save one character by changing the initial (1..9).map{ into 1.upto(9){! – Paul Prestidge – 2013-04-17T23:46:44.307

There are trailing spaces (first 3 lines). The original table doesn't have them. I'm not sure if that makes a difference, though... – Reinstate Monica – 2013-05-13T12:51:44.830

@WolframH, all solutions I checked either have trailing spaces or not reproduce the exact formatting. – manatwork – 2013-05-13T13:03:39.753

4

D, 75 chars

foreach(i,1..10){foreach(j,1..i+1){writef("%dx%d=%d ",i,j,i*j);}writeln();}

you just said code not function or full program

ratchet freak

Posted 2013-04-15T10:57:33.093

Reputation: 1 334

1By default, snippets are not allowed; a function or full program is required. – a spaghetto – 2016-07-26T21:06:26.850

@quartata This answer predates our defaults by a year and a half. – Dennis – 2016-07-26T22:43:48.630

@Dennis Oh, I didn't realize the no snippets allowed rule was that new. Sorry. – a spaghetto – 2016-07-26T23:12:17.133

Would this work? foreach(i,1..10){foreach(j,1..i+1)writef("%dx%d=%d ",i,j,i*j);writeln;} – Zacharý – 2017-07-10T16:52:14.580

4

APL (37)

∆∘.{⊃(⍺≥⍵)/,/(⍕⍺)'×'(⍕⍵)'=',⍕⍺×⍵}∆←⍳9

And it's not even just two for-loops. In APL, the following construct:

x ∘.F y

where x and y are lists, and F is a function, applies F to each pair of items in x and y and gives you a matrix.

So: ∆∘.×∆←⍳9 gets you a multiplication table from 1 to 9. The above function generates the required string for each pair, i.e. (⍕⍺), string representation of the first number, followed by ×, followed by (⍕⍵), string representation of the second number, followed by =, followed by ⍕⍺×⍵, as long as ⍺≥⍵.

marinus

Posted 2013-04-15T10:57:33.093

Reputation: 30 224

4

Perl, 54 Characters

printf"%dx$?=%-3d"x$?.$/,map{$_,$_*$?}1..$?while$?++<9

user7486

Posted 2013-04-15T10:57:33.093

Reputation:

4

APL (Dyalog), 28

↑{⍵{⍕⍵,'×',⍺,'=',⍺×⍵}¨⍳⍵}¨⍳9

Analogous to a double loop in other languages

{⍵{...}¨⍳⍵}¨⍳9 sets up the double loop
⍕⍵,'×',⍺,'=',⍺×⍵ creates the string for each pair
Convert array of array of strings to a matrix of stings

Output

1 × 1 = 1                                                                                                 
1 × 2 = 2  2 × 2 = 4                                                                                      
1 × 3 = 3  2 × 3 = 6   3 × 3 = 9                                                                          
1 × 4 = 4  2 × 4 = 8   3 × 4 = 12  4 × 4 = 16                                                             
1 × 5 = 5  2 × 5 = 10  3 × 5 = 15  4 × 5 = 20  5 × 5 = 25                                                 
1 × 6 = 6  2 × 6 = 12  3 × 6 = 18  4 × 6 = 24  5 × 6 = 30  6 × 6 = 36                                     
1 × 7 = 7  2 × 7 = 14  3 × 7 = 21  4 × 7 = 28  5 × 7 = 35  6 × 7 = 42  7 × 7 = 49                         
1 × 8 = 8  2 × 8 = 16  3 × 8 = 24  4 × 8 = 32  5 × 8 = 40  6 × 8 = 48  7 × 8 = 56  8 × 8 = 64             
1 × 9 = 9  2 × 9 = 18  3 × 9 = 27  4 × 9 = 36  5 × 9 = 45  6 × 9 = 54  7 × 9 = 63  8 × 9 = 72  9 × 9 = 81

TwiNight

Posted 2013-04-15T10:57:33.093

Reputation: 4 187

you could remove some of the commas to the same effect: ↑{⍵{⍕⍵'×'⍺'=',⍺×⍵}¨⍳⍵}¨⍳9 or even make use of the new "key operator": {⍕⍵'×'⍺'=',⍺×⍵}¨∘⍳⌸⍳9 – ngn – 2018-02-04T18:12:37.477

4

Mathematica, 45

Pretty boring, but I guess it serves as a syntax comparison:

Grid@Table[Row@{a, "x", b, "=", a b}, {a, 9}, {b, a}]

Mr.Wizard

Posted 2013-04-15T10:57:33.093

Reputation: 2 481

2What, you're telling me there isn't a builtin for this? – Aaron – 2016-07-26T13:26:21.617

1@Aaron The function bloat of Mathematica doesn't extent that far yet, thankfully. – Mr.Wizard – 2016-07-26T16:08:38.540

3

VBScript (133); without loops.

g=""
sub m(x,y)
    g=x&"x"&y&"="&x*y&vbTab&g
    if x>1 then 
        m x-1,y
    elseif y>1 then 
        g=vbLf&g 
        m y-1,y-1
    end if
end sub
m 9,9
wscript.echo g

On request of the challenger: no loops. This code uses recursive subroutine calls.

AutomatedChaos

Posted 2013-04-15T10:57:33.093

Reputation: 291

3

Maple, 64

seq(printf(seq(printf("%ax%a=%a ",j,i,i*j),j=1..i),"\n"),i=1..9)

DSkoog

Posted 2013-04-15T10:57:33.093

Reputation: 560

3

x86_64 machine code (linux), 175 99 76 bytes

0000000000400080 <_start>:
  400080:   66 bf 09 00             mov    $0x9,%di

0000000000400084 <_table.L2>:
  400084:   6a 0a                   pushq  $0xa
  400086:   89 fe                   mov    %edi,%esi

0000000000400088 <_table.L3>:
  400088:   89 f0                   mov    %esi,%eax
  40008a:   f7 e7                   mul    %edi

000000000040008c <_printInteger>:
  40008c:   6a 20                   pushq  $0x20
  40008e:   3c 0a                   cmp    $0xa,%al
  400090:   7d 02                   jge    400094 <_printInteger.L1>
  400092:   6a 20                   pushq  $0x20

0000000000400094 <_printInteger.L1>:
  400094:   66 31 d2                xor    %dx,%dx
  400097:   b3 0a                   mov    $0xa,%bl
  400099:   66 f7 f3                div    %bx
  40009c:   83 c2 30                add    $0x30,%edx
  40009f:   52                      push   %rdx
  4000a0:   66 85 c0                test   %ax,%ax
  4000a3:   75 ef                   jne    400094 <_printInteger.L1>
  4000a5:   6a 3d                   pushq  $0x3d
  4000a7:   66 57                   push   %di
  4000a9:   80 04 24 30             addb   $0x30,(%rsp)
  4000ad:   6a 78                   pushq  $0x78
  4000af:   66 56                   push   %si
  4000b1:   80 04 24 30             addb   $0x30,(%rsp)
  4000b5:   ff ce                   dec    %esi
  4000b7:   75 cf                   jne    400088 <_table.L3>
  4000b9:   ff cf                   dec    %edi
  4000bb:   75 c7                   jne    400084 <_table.L2>

00000000004000bd <_printChars>:
  4000bd:   66 ba 00 08             mov    $0x800,%dx
  4000c1:   b0 01                   mov    $0x1,%al
  4000c3:   66 bf 01 00             mov    $0x1,%di
  4000c7:   48 89 e6                mov    %rsp,%rsi
  4000ca:   0f 05                   syscall

This is a dump of the binary file, and all of this is 175 bytes. It basically does the same two loops that all the answers do, but printing to the console is a bit harder and basically requires pushing the characters to print onto the stack in reverse, and then making a (linux specific) syscall to actually put those chars into stdout.

I've now optimized this so that only 1 write operation is performed (faster!) and has magic numbers (wow!) and by pushing the entire result onto the stack backwards before making the syscall. I also took out the exit routine because who needs proper exit code?

Here's a link to my first and second attempts, in their original nasm syntax.

I welcome anyone who has any other suggestions on how it can be improved. I can also explain the logic in more detail if anyone is curious.

(Also, it doesn't print the extra spaces to make all the columns aligned, but if that's required I can put the logic in at the cost of a few more bytes).

EDIT: Now prints extra spaces and is golfed down even more! It's doing some pretty crazy stuff with the registers, and is probably unstable if this program were to be expanded.

davey

Posted 2013-04-15T10:57:33.093

Reputation: 321

PPCG requires full programs or functions. Snippets are implicitly disallowed (i.e. you can use them only if the OP has explicitly allowed them.) – Erik the Outgolfer – 2016-07-26T13:57:59.060

Oh, my bad. I forgot OP hadn't specified that. – davey – 2016-07-26T20:59:53.760

3

Javascript, 190 bytes

Late to the party, but I was piqued by @jdstankosky 's comment and decided to take a different approach. Here's a Javascript entry that mauls a template and evals itself along the way.

t="a*b=c ";u="";r=u;for(i=1;i<10;i++){a=0;u=u+t;r+=u.split(' ').map(x=>x.replace('a',++a).replace('b',i)).map(x=>x.replace('*','x').replace('c',eval(x.substr(0,3)))).join(' ')+'\n'}alert(r);

Un-golfed version (slightly older version in which a function returns the table instead of a script alerting it, but the same principles apply):

function f()
{
    t="a*b=c "; // template for our multiplication table
    u="";r="";  // tmp- and return values
    for(i=1;i<10;i++)
    {
        a=0;    // is auto-incremented in MAP
        u=u+t;// extend the template once per iteration
        v=u.split(' '); // Smash the template to pieces
        w=v.map(x=>x.replace('a', ++a).replace('b', i)) // MAP replaces the A and B's with the correct numbers
        w=w.map(x=>x.replace('*', 'x').replace('c', eval(x.substring(0,3)))).join(' '); // second map evals that and replaces c with the answer, makes the asteriks into an X
        r=r+w+'\n'  // results get concatenated
    }
    return r;
}

steenbergh

Posted 2013-04-15T10:57:33.093

Reputation: 7 772

1I made that comment a looong time ago, haha. I'm actually glad to see this. – jdstankosky – 2017-08-10T13:37:52.100

3

Pascal, 128 bytes

One recursive procedure takes care of everything. Call with m(9,9).

procedure m(i,j:integer);begin if i<1then Exit;if i=j then begin m(i-1,j-1);writeln;end;m(i-1,j);write(i,'x',j,'=',i*j,' ');end;

Ungolfed:

procedure mul(i, j: integer);
begin
  if i<1 then
    Exit;
  if i=j then
  begin
    mul(i-1, j-1);
    writeln;
  end;
  mul(i-1, j);
  write(i,'x',j,'=',i*j,' ');
end;

hdrz

Posted 2013-04-15T10:57:33.093

Reputation: 321

3

Fourier, 756 632 bytes

Thanks @BetaDecay for 124 bytes!

1o120~Ea1o61a1o10~Na1oEa2o61a2o32~Saa2oEa2o61a4oNa1oEa3o61a3oSaa2oEa3o61a6oSaa3oEa3o61a9o^a1oEa4o61a4oSaa2oEa4o61a8oSaa3oEa4o61a12oSa4oEa4o61a16oNa1oEa5o61a5oSaa2oEa5o61aNoSa3oEa5o61a15oSa4oEa5o61a20oSa5oEa5o61a25oNa1oEa6o61a6oSaa2oEa6o61a12oSa3oEa6o61a18oSa4oEa6o61a24oSa5oEa6o61a30oSa6oEa6o61a36oNa1oEa7o61a7oSaa2oEa7o61a14oSa3oEa7o61a21oSa4oEa7o61a28oSa5oEa7o61a35oSa6oEa7o61a42oSa7oEa7o61a49oNa1oEa8o61a8oSaa2oEa8o61a16oSa3oEa8o61a24oSa4oEa8o61aSoa5oEa8o61a40oSa6oEa8o61a48oSa7oEa8o61a56oSa8oEa8o61a64oNa1oEa9o61a9oSaa2oEa9o61a18oSa3oEa9o61a27oSa4oEa9o61a36oSa5oEa9o61a45oSa6oEa9o61a54oSa7oEa9o61a63oSa8oEa9o61a72oSa9oEa9o61a81o

Oliver Ni

Posted 2013-04-15T10:57:33.093

Reputation: 9 650

1

I managed to golf 124 bytes off your program by saving the number 120 as the variable E, the number 32 as S and 10 as N.

– Beta Decay – 2016-09-20T17:46:36.057

2

Coreutils/Bash: 147 136 135

for i in {1..9}; do
  yes $'\n' | head -n $[i-1] > $i
  paste -dx= <(yes $i) <(seq $i 9) <(seq $[i*i] $i $[9*i]) |head -n$[10-i] >> $i
done
paste {1..9}

Golfed, using explicit newline and, using deprecated head option (thanks manatwork):

for i in {1..9};do yes '
'|head -$[i-1]>$i;paste -dx= <(yes $i) <(seq $i 9) <(seq $[i*i] $i $[9*i])| head -$[10-i]>>$i;done;paste {1..9}

Output:

1x1=1                               
1x2=2   2x2=4                           
1x3=3   2x3=6   3x3=9                       
1x4=4   2x4=8   3x4=12  4x4=16                  
1x5=5   2x5=10  3x5=15  4x5=20  5x5=25              
1x6=6   2x6=12  3x6=18  4x6=24  5x6=30  6x6=36          
1x7=7   2x7=14  3x7=21  4x7=28  5x7=35  6x7=42  7x7=49      
1x8=8   2x8=16  3x8=24  4x8=32  5x8=40  6x8=48  7x8=56  8x8=64  
1x9=9   2x9=18  3x9=27  4x9=36  5x9=45  6x9=54  7x9=63  8x9=72  9x9=81

Thor

Posted 2013-04-15T10:57:33.093

Reputation: 2 526

Spare 8 characters by replacing all $(( )) arithmetic evaluations with $[ ]; share 2 characters by replacing the $'\n' escaped newline character with a literal one (I mean, yes ' in one line, then ' in the following one); spare 2 characters by not using head's -n option explicitly, just - and the number. – manatwork – 2013-04-17T07:24:33.447

@manatwork: I didn't know about the $[ ] notation, good to know. Replacing -n by - is only one character less so it's 11 in total, thank you very much :). – Thor – 2013-04-17T07:56:48.750

2

vba 55

(immediate window)

for f=1 to 9:for j=1 to f:?f;"x";j;"=";f*j,:next:?:next

note - GWBasic only needs 2 extra characters:

1 for f=1 to 9:for j=1 to f:?f;"x";j;"=";f*j,:next:?:next

SeanC

Posted 2013-04-15T10:57:33.093

Reputation: 1 117

2

Tcl 98 chars

while {[incr a]<10} {set b 0;while {[incr b]<=$a} {puts -nonewline "$a×$b=[expr $a*$b] "};puts ""}

Johannes Kuhn

Posted 2013-04-15T10:57:33.093

Reputation: 7 122

2

Javascript, 75

for(s="",a=b=1;a<10;b=a==b?(a++,alert(s),s="",1):b+1)s+=b+"x"+a+"="+a*b+" "

I wonder if something better than two (combined?) for loops is possible...

tomsmeding

Posted 2013-04-15T10:57:33.093

Reputation: 2 034

well, the only thing I am sure is that it is possible to get 75 on separated loops (my old comment)

– ajax333221 – 2013-05-06T19:14:41.117

2

PowerShell, 54 52 bytes

1..9|%{''+(1..($l=$_)|%{"$_`×$l={0,-2}"-f($_*$l)})}

Try it online!

mazzy

Posted 2013-04-15T10:57:33.093

Reputation: 4 832

2

LOLCODE, 202 bytes

IM IN YR o UPPIN YR b TIL BOTH SAEM b AN 10
c R ""
IM IN YR i UPPIN YR a TIL BOTH SAEM a AN SUM OF b AN 1
c R SMOOSH c SMOOSH a "x" b "=" PRODUKT OF a AN b " " MKAY
IM OUTTA YR i
VISIBLE c
IM OUTTA YR o

Ungolfed:

HAI 1.3 BTW Unnecessary in current implementations
IM IN YR outer UPPIN YR multiplicand TIL BOTH SAEM multiplicand AN 10
    I HAS A output ITZ ""
    IM IN YR inner UPPIN YR multiplier TIL BOTH SAEM multiplier AN SUM OF multiplicand AN 1
        output R SMOOSH output AN SMOOSH multiplier AN "x" AN multiplicand AN "=" AN PRODUCKT OF multiplicand AN multiplier AN " " MKAY MKAY BTW AN is optional to separate arguments, a linebreak is an implicit MKAY.
    IM OUTTA YR inner
    VISIBLE output
IM OUTTA YR outer
KTHXBYE BTW Unnecessary in current implementations

Pythonated for non-leetspeakers:

for multiplicand in range(1, 10):
    output = ""
    for multiplier in range(1, multiplicand + 1):
        output = output + (multiplier + "x" + multiplicand + "=" + str(multiplicand * multiplier) + " ")
    print(output)

OldBunny2800

Posted 2013-04-15T10:57:33.093

Reputation: 1 379

As someone who's also used LOLCODE in a code challenge submission, have my upvote! LOVE this lang – jdstankosky – 2017-08-10T13:39:56.147

2

JAVA, 103 94 92 90 bytes

Using JShell from Java 9 SDK allows me to save large amount of space

for(int i=0,j;i++<9;)for(j=1;j<=i;)System.out.print(i+"*"+j+"="+i*j+"\t"+(j++<i?"":"\n"))

Following Kevin's suggestion I reduced solution by 2 bytes.

Thanks to cliffroot, I was able to reduce it by another 1 byte

user902383

Posted 2013-04-15T10:57:33.093

Reputation: 1 360

1You can save a few bytes by removing the int from the second for-loop, and add ,j to the first. So like this: for(int i=0,j;++i<=9;)for(j=1;j<=i;)System.out.print(i+"*"+j+"="+i*j+"\t"+(j++<i?"":"\n")); – Kevin Cruijssen – 2016-07-26T12:31:55.430

It seems like you can replace ++i<=9 with i++<9 – cliffroot – 2016-07-26T14:06:31.033

2

c#, 142 bytes

Enumerable.Range(1,9).ToList().ForEach(i =>Enumerable.Range(1,i).ToList().ForEach(j=>Console.Write("{0}x{1}={2}{3}",j,i,j*i,j==i?"\n":"\t")));

And not a for in sight...

supermeerkat

Posted 2013-04-15T10:57:33.093

Reputation: 113

ForEach "not a for in sight" well... xD – HyperNeutrino – 2017-09-24T17:59:07.967

2

><>, 50 bytes

1v
 1
?\::n"x"o{::n"="o}*n" "o1+:{:})
 \~1+:a=?;ao

You can try it on the online interpreter.

Note that there is trailing spaces on each lines, which might make it incorrect (OP hasn't stated on this point as of this answer).

Aaron

Posted 2013-04-15T10:57:33.093

Reputation: 3 689

2

///, 268 bytes

/_/\/\///x/×_N/x9=_E/x8=_V/x7=_S/x6=_F/x5=_R/x4=_O/
1_t/  2_h/ 3/1x1=1Ox2=2tx2=4Ox3=3tx3=6 hx3=9OR4tR8 hR12 4R16OF5tF10hF15 4F20 5F25OS6tS12hS18 4S24 5S30 6S36OV7tV14hV21 4V28 5V35 6V42 7V49OE8tE16hE24 4E32 5E40 6E48 7E56 8E64ON9tN18hN27 4N36 5N45 6N54 7N63 8N72 9N81

Erik the Outgolfer

Posted 2013-04-15T10:57:33.093

Reputation: 38 134

2

C 79 bytes

i=1,j=1;f(){printf("%dx%d=%d ",j,i,i*j);++i>j?++j,i=1,j<=9?puts(""),f():0:f();}

the main

main(){f();}

the table

1x1=1 
2x1=2 2x2=4 
3x1=3 3x2=6 3x3=9 
4x1=4 4x2=8 4x3=12 4x4=16 
5x1=5 5x2=10 5x3=15 5x4=20 5x5=25 
6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=36 
7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49 
8x1=8 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64 
9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81 

RosLuP

Posted 2013-04-15T10:57:33.093

Reputation: 3 036

1

Perl: 65 , 62 characters

map{map{printf"%dx%d=%2d ",$_,$i,$_*$i}1..($i=$_);print$/}1..9

Toto

Posted 2013-04-15T10:57:33.093

Reputation: 909

Spare 2 characters by removing the printf's parenthesis; spare 1 character by moving the assignment of $i into the range expression: map{map{printf"%dx%d=%2d ",$_,$i,$_*$i}1..($i=$_);print$/}1..9. – manatwork – 2013-04-17T07:15:06.503

@manatwork: Thank you very much. – Toto – 2013-04-17T07:33:43.413

1

Javascript: 82 characters

o="";for(a=1;a<10;a++){for(b=1;b<=a;b++){o+=a+"x"+b+"="+(a*b)+" "}o+="\n"}alert(o)

Mike Clark

Posted 2013-04-15T10:57:33.093

Reputation: 171

I will be picky but 4x4 is not directly under 5x4 like in task. – user902383 – 2016-07-26T13:02:11.680

1your code can be shortened to 75 like this for(i=0,s="";9>i++;){for(j=0;j++<i;)s+=j+"x"+i+"="+j*i+" ";s+="\n"}alert(s), however the double spaces thing on 2 digits is not respected, I was about to submit that one but using +(9<i*j?" ":" ") instead of just +" " edit: on the ternary the double spaces disappeared, but they are on the second param – ajax333221 – 2013-05-06T18:55:42.553

1

Python: 87

I'm eyeballing the solutions others have posted and most of them don't appear to get the spacing correct.

for i in range(1,10):print''.join(('%s×%s=%s'%(j,i,i*j)).ljust(7)for j in range(1,i+1))

Fraxtil

Posted 2013-04-15T10:57:33.093

Reputation: 2 495

You have trailing spaces, does that count? ;-) – Reinstate Monica – 2013-05-13T12:55:24.063

1

Python (79)

or (77) if I use range(10) except that produces an empty line at the start

for i in range(1,10):print' '.join('%dx%d=%-2d'%(j,i,j*i)for j in range(1,i+1))

1x1=1 
1x2=2  2x2=4 
1x3=3  2x3=6  3x3=9 
1x4=4  2x4=8  3x4=12 4x4=16
1x5=5  2x5=10 3x5=15 4x5=20 5x5=25
1x6=6  2x6=12 3x6=18 4x6=24 5x6=30 6x6=36
1x7=7  2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49
1x8=8  2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64
1x9=9  2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81

jamylak

Posted 2013-04-15T10:57:33.093

Reputation: 420

1

Ruby: 79 77 characters (without loops)

m=->i,j{"%dx%d=%-3d"%[i,j,i*j]+(i<j ?m[i+1,j]:j<9?$/+m[1,j+1]:$/)};$><<m[1,1]

Sample run:

bash-4.2$ ruby -e 'm=->i,j{"%dx%d=%-3d"%[i,j,i*j]+(i<j ?m[i+1,j]:j<9?$/+m[1,j+1]:$/)};$><<m[1,1]' 
1x1=1  
1x2=2  2x2=4  
1x3=3  2x3=6  3x3=9  
1x4=4  2x4=8  3x4=12 4x4=16 
1x5=5  2x5=10 3x5=15 4x5=20 5x5=25 
1x6=6  2x6=12 3x6=18 4x6=24 5x6=30 6x6=36 
1x7=7  2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49 
1x8=8  2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64 
1x9=9  2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81 

manatwork

Posted 2013-04-15T10:57:33.093

Reputation: 17 865

1

C++, 126 characters

I took the expected approach.

#include <iostream>
int main(){for(int i=1,j;i<10;i++){for(j=1;j<=i;j++)std::cout<<i<<"x"<<j<<"="<<i*j<<" ";std::cout<<std::endl;}}

Cisplatin

Posted 2013-04-15T10:57:33.093

Reputation: 403

1

Python 2, 72

i=1;exec"j=1;exec'print\"%sx%s=%-2s\"%(j,i,j*i),;j+=1;'*i;print;i+=1;"*9

Output:

1x1=1 
1x2=2  2x2=4 
1x3=3  2x3=6  3x3=9
1x4=4  2x4=8  3x4=12 4x4=16
1x5=5  2x5=10 3x5=15 4x5=20 5x5=25
1x6=6  2x6=12 3x6=18 4x6=24 5x6=30 6x6=36
1x7=7  2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49
1x8=8  2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64
1x9=9  2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81

flornquake

Posted 2013-04-15T10:57:33.093

Reputation: 1 467

1

PHP, 73 bytes

for(;$m++<9;print"
")for($n=0;$n++<$m;)printf("%d×%d=%-3d",$n,$m,$n*$m);

Try it online!

Jörg Hülsermann

Posted 2013-04-15T10:57:33.093

Reputation: 13 026

1

05AB1E, 22 20 bytes

9LεLyâε'×ý'=yPðJ6∍]»

-2 bytes thanks to @Grimmy.

Try it online.

Explanation:

9L                 # Push a list in the range [1,9]
  ε                # Map over each value `y`:
   L               #  Push a list in the range [1,y]
    yâ             #  Pair each value in this list with `y`
                   #   i.e. [1,2,3] and 3 → [[1,3],[2,3],[3,3]]
      ε            #  Map over each pair:
       '×ý        '#   Join the pair with "×" delimiter
          '=      '#   Push a "="
            yP     #   Push the pair again, and pop and push it's product
              ð    #   Push a space " "
               J   #   Join all three values on the stack together
                6∍ #   And then shorten the string to size 6
  ]                # Close both the maps
   »               # Join each inner list by spaces, and then each string by newlines
                   # (after which the result is output implicitly)

Kevin Cruijssen

Posted 2013-04-15T10:57:33.093

Reputation: 67 575

δ‚ => â for -1. – Grimmy – 2020-02-21T11:56:53.750

And here’s 20 using J instead of ý + «.

– Grimmy – 2020-02-21T11:59:12.503

@Grimmy Ah, of course. Thanks! :) – Kevin Cruijssen – 2020-02-21T12:02:14.790

1

Burlesque, 45 bytes

9roJcp:SOm{Jpdjimup"x="**j_+}{-]j-]==}gb)wduN

Try it online!

I'm almost positive there're multiple cuts that can be made here, but I just can't get them...

9ro     # Range [1,9]
J       # Duplicate
cp      # Cartesian product
:SO     # Filter for sorted-reversed
m{      # Map
 J      # Duplicate
 pd     # Product
 jimup  # Convert the two numbers into a string ({1 1} => "11")
 "x="** # Riffle in x=                          ("11""x=" => "1x1=")
 j_+    # Append the result
 }
 {
  -]j-] # Heads of both
  ==    # Are equal
 }gb    # Group by first digit being the same
 )wd    # Separate each internal list by spaces
 uN     # Separate main list by newline and prettify

DeathIncarnate

Posted 2013-04-15T10:57:33.093

Reputation: 916

1

C, 86 85 84 bytes

i;m(j){for(;i++^9;puts(""))for(j=0;j++^i;printf("%d×%d=%d %c",j,i,j*i,j*i>9?:32));}

o79y

Posted 2013-04-15T10:57:33.093

Reputation: 509

j*v>9?:32 what does it mean? – RosLuP – 2016-09-20T14:59:27.687

jv>9?:32 it seems as jv>9?0:32 but j*v>9?32: here seems not compile... – RosLuP – 2016-09-20T15:28:16.893

ideone @RosLuP – o79y – 2016-09-20T23:38:05.343

Yes code as "a>b?9:;" I remember not compile in Ideone but code as "a>b?:9;" compile... – RosLuP – 2016-09-21T07:07:07.053

1

k (63 characters)

Prints the output to stdout.

-1@`/:" "/:'{7$x,"×",y,"=",z}.''$v,''(*).''v:(1+!:'t),''t:1+!9;

Example

k)-1@`/:" "/:'{7$x,"×",y,"=",z}.''$v,''(*).''v:(1+!:'t),''t:1+!9;
1×1=1 
1×2=2  2×2=4 
1×3=3  2×3=6  3×3=9 
1×4=4  2×4=8  3×4=12 4×4=16
1×5=5  2×5=10 3×5=15 4×5=20 5×5=25
1×6=6  2×6=12 3×6=18 4×6=24 5×6=30 6×6=36
1×7=7  2×7=14 3×7=21 4×7=28 5×7=35 6×7=42 7×7=49
1×8=8  2×8=16 3×8=24 4×8=32 5×8=40 6×8=48 7×8=56 8×8=64
1×9=9  2×9=18 3×9=27 4×9=36 5×9=45 6×9=54 7×9=63 8×9=72 9×9=81

skeevey

Posted 2013-04-15T10:57:33.093

Reputation: 4 139

1

VBA, 118 bytes

Sub M()
While B<9
B=1-B*(B<>A)
A=A-(B=1)
S=S &B &"x"&A &"="&A*B &IIf(A=B,vbLf,Space(2+(A*B>9)))
Wend
MsgBox S
End Sub

No for loops :-) and only one while loop.

And no If statements, so I could potentially one-line it and get the automatic "End Sub" for 8 fewer bytes if pushed; but I'm not that close to the leaderboard :-)

Sub M():While B<9:B=1-B*(B<>A):A=A-(B=1):S=S &B &"x"&A &"="&A*B &IIf(A=B,vbLf,Space(2+(A*B>9))):Wend:MsgBox S

Joffan

Posted 2013-04-15T10:57:33.093

Reputation: 832

1

Python 2, 91 characters

for k in[" ".join(["%ix%i=%i"%(j,i,j*i)for j in range(1,i+1)])for i in range(1,10)]:print k

Or, if each line as string like '1x2=2 2x2=4' is acceptable, this is 85 characters:

for k in[" ".join(["%ix%i=%i"%(j,i,j*i)for j in range(1,i+1)])for i in range(1,10)]:k

This one is slightly varied, resulting 93 characters:

print("\n".join([" ".join(["%ix%i=%i"%(j,i,j*i)for j in range(1,i+1)])for i in range(1,10)]))

eaydin

Posted 2013-04-15T10:57:33.093

Reputation: 111

1This gives me syntax errors. Which version of python are you using? – James – 2016-07-23T21:38:36.913

Which one gave you a syntax error? All of them?

Python 2.7.11 (default, Jan 22 2016, 08:29:18) [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin – eaydin – 2016-07-24T15:43:58.297

You're probably using Python3, in which case you should use print(k) instead of "print k" for the first solution. – eaydin – 2016-07-24T15:45:52.650

@nukacolacolic You should probably mention in your post or in your heading that some or all of your code only works for Python 2 and not Python 3. It helps when other people want to check your answers. – Sherlock9 – 2016-07-26T14:40:22.957

You're right @Sherlock9 I'll edit the answer, thanks. – eaydin – 2016-07-26T21:28:51.473

1

Convex, 27 bytes

9´{_´f{æ*'×@@'=\_s,¿)S*}N}%

Try it online!

Use the following version if only a single space is required between each equation:

Convex, 21 bytes

9´{_´f{æ*'×@@'=\S}N}%

Try it online!

GamrCorps

Posted 2013-04-15T10:57:33.093

Reputation: 7 058

1

Pyke, 17 16 bytes (noncompeting)

Pyke was created after this question was asked

TFjSF\xj\=ij*s(P

Try it here!

TFj           (  - for j in range(10):
   SF         (  -     for i in range(1,j+1):
     \xj\=ij*s   -         sum(i,"x",j,"=",i*j)
               P - pretty_print(^)

Blue

Posted 2013-04-15T10:57:33.093

Reputation: 26 661

1

Javascript (using external library) (74 bytes)

n=>_.Range(1,9).WriteLine(v=>_.Range(1,v).Write(" ",x=>v+"x"+x+"="+(v*x)))

Link to lib: https://github.com/mvegh1/Enumerable

Code explanation: Create a range starting from 1, for 9 elements. For each integer in the range, write a line according to the predicate accepting the current value as the input param.

Each line in WriteLine will create a range from 1 to v, and write a space delimited string where each integer in the 1 to v sequence is mapped to the multiplication equation

enter image description here

applejacks01

Posted 2013-04-15T10:57:33.093

Reputation: 989

1

Kotlin, 73 bytes

(1..10).forEach{(1..it).forEach{x->print("${x}x$it=${x*it} ")};println()}

Kotlin is the latest JVM language and I mainly wanted to try my hand at it.

You can try it on their online interpreter.

Aaron

Posted 2013-04-15T10:57:33.093

Reputation: 3 689

1

Groovy, 65 60 characters

1.upto(9){x->1.upto(x){printf(x+"x$it=%-3d",x*it)}println()}

Sample run:

bash-4.3$ groovy -e '1.upto(9){x->1.upto(x){printf(x+"x$it=%-3d",x*it)}println()}'
1x1=1  
2x1=2  2x2=4  
3x1=3  3x2=6  3x3=9  
4x1=4  4x2=8  4x3=12 4x4=16 
5x1=5  5x2=10 5x3=15 5x4=20 5x5=25 
6x1=6  6x2=12 6x3=18 6x4=24 6x5=30 6x6=36 
7x1=7  7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49 
8x1=8  8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64 
9x1=9  9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81 

manatwork

Posted 2013-04-15T10:57:33.093

Reputation: 17 865

1

golflua, 54 49 characters

~@i=1,9~@j=1,i I.w(S.q(i.."x%d=%-3d",j,i*j))$w()$

Sample run:

bash-4.3$ golflua -e '~@i=1,9~@j=1,i I.w(S.q(i.."x%d=%-3d",j,i*j))$w()$'
1x1=1  
2x1=2  2x2=4  
3x1=3  3x2=6  3x3=9  
4x1=4  4x2=8  4x3=12 4x4=16 
5x1=5  5x2=10 5x3=15 5x4=20 5x5=25 
6x1=6  6x2=12 6x3=18 6x4=24 6x5=30 6x6=36 
7x1=7  7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49 
8x1=8  8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64 
9x1=9  9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81 

manatwork

Posted 2013-04-15T10:57:33.093

Reputation: 17 865

1

Julia (236 Bytes, potentially 63) - Could use help.

A=[1 2 3 4 5 6 7 8 9; 1 2 3 4 5 6 7 8 9; 1 2 3 4 5 6 7 8 9; 1 2 3 4 5 6 7 8 9; 1 2 3 4 5 6 7 8 9; 1 2 3 4 5 6 7 8 9; 1 2 3 4 5 6 7 8 9; 1 2 3 4 5 6 7 8 9;1 2 3 4 5 6 7 8 9]
map(x->x>0?print(x,"x",x,"=",x*x,"\t"):println(),triu!(A'))

Someone put in the comments "Who's going to do anything but use 2 loops?"

This guy is!

I don't know how to instantiate matrices easily in Julia, anyone who could help me do the instantiation of the matrix better I will be grateful. I can only get it to make a 2D array, and triu doesn't work on that.

How it works:

  • A = [...] creates a 9x9 matrix with 1-9 in each vector (someone please teach me to do this right without accidentally creating a 2D array... I want to learn this language better, but I'm confused on the typing differences and a lot of the documentation is pretty terse for matrices.
  • triu!(A') takes the inverse of the upper triangle of the matrix.
  • map(x->x?0...:...,A) mapping function that differentiates on x=0, printing a newline when needed.

Output:

1×1=1 
1×2=2  2×2=4 
1×3=3  2×3=6  3×3=9 
1×4=4  2×4=8  3×4=12 4×4=16
1×5=5  2×5=10 3×5=15 4×5=20 5×5=25
1×6=6  2×6=12 3×6=18 4×6=24 5×6=30 6×6=36
1×7=7  2×7=14 3×7=21 4×7=28 5×7=35 6×7=42 7×7=49
1×8=8  2×8=16 3×8=24 4×8=32 5×8=40 6×8=48 7×8=56 8×8=64
1×9=9  2×9=18 3×9=27 4×9=36 5×9=45 6×9=54 7×9=63 8×9=72 9×9=81

Magic Octopus Urn

Posted 2013-04-15T10:57:33.093

Reputation: 19 422

That was my comment! Lol, it's been some years. – jdstankosky – 2017-08-10T13:33:35.120

0

C#, 131:

Action<string> n=x=>Console.Write(" "+x);Action f=()=>{for(int i=1,x=1;i<10;i++){for(;x<=i;x++){n(x+"x"+i+"="+i*x);}n("\n");x=1;}};

Isn't the EXACT shape, but nearly there.

It'sNotALie.

Posted 2013-04-15T10:57:33.093

Reputation: 209

I'm not sure about the rules, but, isn't your code supposed to include all that is necessary to compile ? – None – 2013-05-18T00:36:34.120

I think I saw somewhere that putting an action is fine in C#. – It'sNotALie. – 2013-05-18T07:00:31.883

0

Erlang escript 99

$ cat multi 

main(_)->[[[io:format("~bx~b=~-3b",[B,A,A*B])||B<-s(A)],io:nl()]||A<-s(9)].
s(X)->lists:seq(1,X).

and run

$ escript multi 
1x1=1  
1x2=2  2x2=4  
1x3=3  2x3=6  3x3=9  
1x4=4  2x4=8  3x4=12 4x4=16 
1x5=5  2x5=10 3x5=15 4x5=20 5x5=25 
1x6=6  2x6=12 3x6=18 4x6=24 5x6=30 6x6=36 
1x7=7  2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49 
1x8=8  2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64 
1x9=9  2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81

Hynek -Pichi- Vychodil

Posted 2013-04-15T10:57:33.093

Reputation: 350

0

tcl, 93

time {incr i;set j 0;while {[incr j]<=$i} {puts -nonewline $j\x$i=[expr $j*$i]\ };puts ""} 10

demo

sergiol

Posted 2013-04-15T10:57:33.093

Reputation: 3 055

Alternative approach with same number of bytes: http://rextester.com/KPMD20731

– sergiol – 2017-07-09T19:42:21.657

0

Python 3.6, 70 68 bytes

r=range(1,10)
for b in r:print(*[f"{a}x{b}={a*b:<2}"for a in r[:b]])

Try it online!

GarethPW

Posted 2013-04-15T10:57:33.093

Reputation: 1 119

I had not seen Daniel's Answer before submitting this, but credit to him for the original implementation of this idea.

– GarethPW – 2017-07-09T21:09:35.327

168 bytes – ovs – 2018-01-31T19:31:43.600

0

///, 262 bytes

/;/=4//:/x\/\///-/ 6:,/=2//'/ 5:&/=1//%/ 4:#/ 3:"/
1:!/  2x/1x1&"2,!2;"3=3!3=6 #3=9"4;!4=8 #4&2%4&6"5=5!5&0#5&5%5,0'5,5"6=6!6&2#6&8%6,4'6=30-6=36"7=7!7&4#7,1%7,8'7=35-7;2 7x7;9"8=8!8&6#8,4%8=32'8;0-8;8 7x8=56 8x8=64"9=9!9&8#9,7%9=36'9;5-9=54 7x9=63 8x9=72 9x9=81

Try it online!

Conor O'Brien

Posted 2013-04-15T10:57:33.093

Reputation: 36 228

0

Excel VBA, 88 76 74 73 Bytes

No For loops

Anonymous VBE Immediate window function that takes no input and outputs to range [A1:I9] on the ActiveSheet object

[1:9]="=If(Column()>Row(),"""",Row()&""x""&Column()&""=""&Row()*Column())

-12 Bytes for removing A1 in all Column(...) and Row(...) calls

-2 Bytes for changing [A1:I9] to [1:9]

Output

enter image description here

Taylor Scott

Posted 2013-04-15T10:57:33.093

Reputation: 6 709

0

JavaScript, 70 characters

for(s=i='';i++<9;s+='\n')for(j=0;j++<i;s+=j+'×'+i+'='+j*i+' ');alert(s)

Respecting alignment, 83 characters:

for(s=i='';i++<9;s+='\n')for(j=0;j++<i;s+=j+'×'+i+'='+j*i+(j*i>9?' ':'  '));alert(s)

Tomas Langkaas

Posted 2013-04-15T10:57:33.093

Reputation: 324

0

Haskell, 84 82 bytes

putStr$init$unlines[unwords[s i++'×':s j++'=':s(i*j)|i<-[1..j]]|j<-[1..9]]
s=show

-2 thanks to @Laikoni!

Try it online!

ბიმო

Posted 2013-04-15T10:57:33.093

Reputation: 15 345

0

Perl 5, 51 bytes

for$/(1..9){printf$_."x$/=%-3d",$_*$/for 1..$/;say}

Try it online!

Xcali

Posted 2013-04-15T10:57:33.093

Reputation: 7 671

0

Japt, 23 bytes

9õÈõ_[X'×Z'=X*Z]¬ú6ø÷

Try it


Explanation

9õ                          :Range [1,9]
  È                  Ã      :Pass each integer X through a function
   õ                        :  Range [1,X]
    _              Ã        :  Pass each integer Z through a function
     [X'×Z'=X*Z]            :    Array [X,"×",Z,"=",X*Z]
                ¬           :    Join to a string
                 ú6         :    Pad end with spaces to length 6
                    ¸       :  Join with spaces
                      ·     :Join with newlines

Shaggy

Posted 2013-04-15T10:57:33.093

Reputation: 24 623

0

Excel VBA, 83 Bytes

Anonymous VBE immediate window function that takes no input and outputs to the VBE immediate window.

For y=1To 9:For x=1To 9:?IIf(x<=y,Left(x &"x"&y &"=" &x*y &"  ",7),"");:Next:?:Next

Taylor Scott

Posted 2013-04-15T10:57:33.093

Reputation: 6 709

0

uBASIC, 87 bytes

Anonymous function that takes no input and outputs to the console.

0ForY=1To9:ForX=1To9:z=x*y:Ifx<=yThen?x;"x";y;"=";z;" ";:Ifz<10Then?" ";
2NextX:?:NextY

Try it online!

Taylor Scott

Posted 2013-04-15T10:57:33.093

Reputation: 6 709

0

Yabasic, 101 bytes

Anonymous function that takes no input and prints a multiplication table to the console.

For y=1To 9
For x=1To 9
If(x<=y)Then
?Left$(Str$(x)+"x"+Str$(y)+"="+Str$(x*y)+"  ",7);
Fi
Next
?
Next

-3 bytes for the use of Fi over EndIf

Try it online!

Taylor Scott

Posted 2013-04-15T10:57:33.093

Reputation: 6 709

0

MY-BASIC, 105 bytes

Anonymous function that takes no input and prints a multiplication table to the console.

Str(...) conversions are costly in this solution.

For Y=1 To 9
For X=1 To 9
If x<=y Then Print Left(Str(x)+"x"+Str(y)+"="+Str(x*y)+"  ",7)
Next
Print;
Next

Try it online!

Taylor Scott

Posted 2013-04-15T10:57:33.093

Reputation: 6 709

0

Pyth, 25 bytes, non-competing

Non-competing because the language postdates the challenge

Now fully conformant!

VS9jdm.[s[N\×d\=*Nd)\ 6SN

Try it online!

robbie

Posted 2013-04-15T10:57:33.093

Reputation: 427

0

Javascript, ES6 65

for(i=0,r='';++i<10;r+='\n')for(e=0;e++<i;r+=i+'x'+e+'='+i*e+' ');

It was pretty fun to make!

Afonso Matos

Posted 2013-04-15T10:57:33.093

Reputation: 312

Nice solution. However, your code does not output anything, and it does not include the required double spaces for alignment. With these added, your solution clocks in at 85 characters: for(i=r="";10>++i;r+="\n")for(e=0;e++<i;r+=i+"x"+e+"="+i*e+(10>e*i?" ":" "));alert(r) – Tomas Langkaas – 2017-06-18T12:35:43.440

0

C 95 bytes

i=1,j=1;f(){printf("%dx%d=%d %c",j,i,i*j,i!=2||j>4?:32);++i>j?++j,i=1,j<=9?puts(""),f():0:f();}

they want this table:

1x1=1 
2x1=2 2x2=4  
3x1=3 3x2=6  3x3=9 
4x1=4 4x2=8  4x3=12 4x4=16 
5x1=5 5x2=10 5x3=15 5x4=20 5x5=25 
6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=36 
7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49 
8x1=8 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64 
9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81 

RosLuP

Posted 2013-04-15T10:57:33.093

Reputation: 3 036

0

Racket 94 bytes

(for((n(range 1 10)))(for((i(range 1(add1 n))))(printf "~ax~a=~a  "i  n(* i n)))(displayln""))

Ungolfed:

(define (f)
  (for ((n (range 1 10)))
    (for ((i (range 1 (add1 n))))
      (printf "~ax~a=~a  " i  n (* i n)))
    (displayln ""))
  )

Testing:

(f)

Output:

1x1=1  
1x2=2  2x2=4  
1x3=3  2x3=6  3x3=9  
1x4=4  2x4=8  3x4=12  4x4=16  
1x5=5  2x5=10  3x5=15  4x5=20  5x5=25  
1x6=6  2x6=12  3x6=18  4x6=24  5x6=30  6x6=36  
1x7=7  2x7=14  3x7=21  4x7=28  5x7=35  6x7=42  7x7=49  
1x8=8  2x8=16  3x8=24  4x8=32  5x8=40  6x8=48  7x8=56  8x8=64  
1x9=9  2x9=18  3x9=27  4x9=36  5x9=45  6x9=54  7x9=63  8x9=72  9x9=81  

rnso

Posted 2013-04-15T10:57:33.093

Reputation: 1 635