Multiply two numbers

Input: Two decimal integers. These can be given to the code in standard input, as arguments to the program or function, or as a list.

Output: Their product, as a decimal integer. For example, the input 5 16 would lead to the output 80.

Restrictions: No standard loopholes please. This is , answer in lowest amount of bytes wins.

Notes: Layout stolen from my earlier challenge, Add two numbers.

Test cases:

1 2   -> 2
4 5   -> 20
7 9   -> 63
-2 8  -> -16
8 -9  -> -72
-8 -9 -> 72
0 8   -> 0
0 -8  -> 0
8 0   -> 0
-8 0  -> 0
0 0   -> 0


Or as CSV:

a,b,c
1,2,2
4,5,20
7,9,63
-2,8,-16
8,-9,-72
-8,-9,72
0,8,0
0,-8,0
8,0,0
-8,0,0
0,0,0


var QUESTION_ID=106182,OVERRIDE_USER=8478;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

• @FlipTack That's assuming addition and multiplication are as easy in any language, which I don't know if it's actually true. – Fatalize Jan 9 '17 at 8:13
• I don't think it's fair to allow the "add two numbers" challenge but close this one. Even though it's very trivial in most programming languages, it's still a valid challenge. If this is too broad, then the "add two numbers" challenge must also be too broad. – Mego Jan 9 '17 at 8:42
• Anyone is free to downvote trivial challenges if they don't like them, but this is a perfectly valid and on-topic challenge and it's nowhere near "too broad" (if anything, you might call a trivial challenge too narrow). I'm reopening this. That said, if anyone feels that trivial challenges insult their intelligence, I encourage them to seek out languages that make the task less trivial. – Martin Ender Jan 9 '17 at 9:19
• Uo next: Subtract two numbers! – steenbergh Jan 9 '17 at 12:57
• @wat Leaving no barrel-bottom unscraped, eh? – Gareth Jan 10 '17 at 12:39

Forth, 1 bytes

*


* pops off the top 2 items from the stack, multiplies them and pushes the result.

• You can just use *, since it's a word/function. I added it to this polyglot answer – mbomb007 Feb 17 '17 at 19:07

Maple, 3 bytes

*


Usage:

*(a,b);


Returns:

a*b


Using this notation, is it possible to supply any number of arguments to the multiplication operator and it will return the product of the sequence.

Röda 0.11, 11 bytes

f&a,b{a*=b}


Try it online!

It modifies its first argument (which must be a variable).

Röda 0.12, 7 bytes (non-competing)

{[_*_]}


Try it online!

This kind of syntax was not supported at the time the challenge was posted. It's an anonymous function that reads to numbers from the stream

><>, 3 + 3 = 6 bytes

*n;


Invoke as fish.py -c '*n;' -v 2 -8, which is why I only count the flag once.

AHK, 15 bytes

1*=%2%
Send,%1%


1 and 2 are, by default, the first two arguments passed in to a program. Sometimes you have to escape them with percent signs so it doesn't confuse the variable 1 with the number one.

HEX, 69 bytes non-competing

GBL;
Listen("1");
Listen("2");
Breed("1" * "2");
Scuttle("1");
Write;


I have no idea when HEX was created, but I've listed this as non-competing as the language currently has no publicly-available functional interpreter.

• ... so how can it be tested? – Stewie Griffin May 16 '17 at 8:16
• @StewieGriffin Write your own interpreter ;) – Skidsdev May 16 '17 at 8:16
• On a more serious note, I'm working on finishing my HEX interpreter, and while it supports GBL, Listen, Breed, Scuttle and Write, so would work for this program, it's still missing most of HEX's features, so it's not public yet. – Skidsdev May 16 '17 at 8:19

Braingolf, 1 byte [non-competing]

*


Try it online!

Implicit input, * multiplies the last 2 number on the stack and pushes the result, implicit output.

Here's a slightly more interesting one:

Braingolf, 9 bytes [non-competing]

<2->[.]&+


Try it online!

Implicit input of x and y. Subtracts 2 from x, (because [] is a do-while and we already have one y), then duplicates y x times, finally, sums the entire stack. Implicit output.

Triangular, 6 bytes

$.$%*<


Try it online!

Formats into this triangle;

  $.$
% * <


Without directionals/no-ops, this looks like: *%

• $ - read input as integer • * - multiply • % - print as integer Decimal, 12 bytes 81D81D43D301  Reads two integers (separated by a space or newline), multiplies them, and prints them to STDOUT. Ungolfed: 81D ; builtin 1 - read INT to stack 81D ; builtin 1 - read INT to stack 43D ; math, multiply (postfix *) 301 ; print from stack to standard output  Try it online! Casio Basic, 6 bytes a*b  No surprises there. 3 bytes for the program, and 3 bytes to add a,b as parameters. Carrot, 5 bytes $^F*$ Takes the input separated by newlines. Explanation: $ //Set the string stack to the first line of the input
^ //Change to operations mode
F //Convert to float stack
* //Multiply the stack by
$//The second line of the input //Implicitly output the result  Jellyfish, 6 bytes P*i i  Try it online! P denotes print, then * multiplies the two numbers below and to the right. At the start of execution, the two is are replaced with values from STDIN. C, 48 bytes main(a,b){scanf("%d%d",&a,&b);printf("%d",a*b);}  New to code golf, any suggestions are welcome. cQuents, 6 bytes #|1:AB  I really need to implement a byte that simply shorthands #|1: because every "perform this operation once" challenge uses that as the beginning. Try it online! Explanation #|1 Add a 1 to the end of the user's input, it will be n : Mode : (sequence 1: given n, output the nth item in the sequence) AB Each item in the sequence is the first input times the second input  Tcl, 10 bytes expr$a*$b  Try it online! If one states namespace path tcl::mathop  before then * acts like a procedure: Tcl, 7 bytes *$a \$b


Try it online!

QC 4 bytes

QQGN

Requires a newer version which must be compiled manually.

Q Read number from stdin and push to stack
Q Same as above
G Multiply two numbers from stack
N Pop and print number from stack


[C64, BasicV2], 11 bytes

1rEA,B:?A*B


The input can be given like:

0dA45,45

• 0 INPUTA,B:?A*B Note that Commodore BASIC keyword abbreviations doesn't save BASIC bytes, only typing – Shaun Bebbers Jan 16 '18 at 10:30
• @ShaunBebbers As far I know, it is opposite: Basic programs are stored in a tokenized form in the memory, thus even if you write the whole PRINT command, it will be stored as ?. It shows as PRINT only if you LIST it. But it is not very important, because the task is to minimize the code size, not the basic byte size. – peterh - Reinstate Monica Jan 16 '18 at 10:42

Batch File, 23 bytes

@set/ak=%1*%2
@echo %k%


Batch doesn't allow you to print the result of an operation; Thus, we are required to create a temporary variable k which contains the result of the multiplication between argument 1 and 2.

The @'s in front of the commands prevent the current path from being printed before each line on the command prompt.

Falcon, 34 bytes

a=int(input())
b=int(input())
>a*b


Try it online!

Falcon uses a similar syntax to Python. Its output, however, has these awesome aliases called "fast-printing" (as per the documentation):

• printl() can be written as >

• print() can be written as >>

Excel VBA, 8 Bytes

Takes input from cells A1 and B1 and outputs to the VBA immediates window

?[A1*B1]


which is functionally equivalant to

Print ActiveSheet.Range("A1").Value * ActiveSheet.Range("B1").Value


Verbosity, 392 bytes

Include<Input>
Include<Output>
Include<Integer>
Include<MetaFunctions>
Input:DefineVariable<i; 0>
Output:DefineVariable<o; 0>
Integer:DefineVariable<r; Integer:Product<f; s>>
Output:DisplayAsText<o; r>
DefineMain<> [
MetaFunctions:ExecuteScript<MetaFunctions@FILE>
]


Try it online!

Whispers, 35 bytes

> Input
> Input
>> 1×2
>> Output 3


Try it online!

Pyth - 5 bytes

AQ*GH


Explanation:

AQ*GH
A     Set G and H to the first two elements of
Q    Evaluated input
Implicitly print
G  G
*   Times
H H

• 3 bytes – hakr14 Aug 13 '18 at 3:07

Implicit, 1 byte

*


Implicit input of two integers, multiply them, implicit output. Try it online!

Wumpus, 5 bytes

II*O@


Try it online!

Explanation

Straight-forward and boring:

I   Read the first integer.
*   Multiply them.
O   Output the result.
@   Terminate the program.


JavaScript (Node.js), 9 bytes

a=>b=>a*b


Try it online!

Red, 16 bytes

func[a b][a * b]


Try it online!

FRACTRAN, 22 bytes

78/55 5/3 1/5 11/2 5/7


Take 7^a*11^b as input, return 11^b*13^(a*b).

Try it online!

This is a golfed version of the wikipedia example.

I'm not sure whether or not extra bytes should be added for input encoding and output decoding.

T-SQL, 17 bytes

SELECT a*b FROM t


Per our IO rules, SQL can take input from a pre-existing table t with integer columns a and b.

This has the bonus of working on an unlimited* number of provided pairs, if they are included in the input table.

*Well, limited only by SQL storage bounds, which are pretty darn high, using enterprise versions.

Brainfuck, 76 bytes

Not the shortest but my own solution, written a long time ago.

Golfed

>[-]>[-]>[-]<<<<[->>>+<<<]>[->+>>+<<<]>[-<+>]>>[-<[-<+<<+>>>]<[->+<]>>]<<<<.


Explanation

x = x*y
(x)(y)(temp0)(xtemp)(ycount)
Own work! Convoluted solution

,               x
> +++           y=3 (or input)

>[-]>[-]>[-]    set cells to 0
<<<< [->>>+<<<] transfer x to xtemp
> [->+>>+<<<]   transfer y to temp0 and ycount
> [-<+>]        transfer temp0 to y
>>
[               while ycount != 0
-               ycount decrement
< [-<+<<+>>>]   transfer xtemp to x and temp0
< [->+<]        transfer temp0 to xtemp
>>
]

<<<< .          x (might overflow)