g | x | w | all
Bytes Lang Time Link
002Uiua241128T042009ZErikDaPa
007Raku Perl 6 rakudo250424T164200Zxrs
030SAKO250325T195909ZAcrimori
006BrainChild ASM241128T043333ZATaco
6166Piet + asciipiet250325T232723Zanderium
024Tcl170502T224653Zsergiol
008brainfuck170503T011932ZDennis
049Bespoke250311T160341ZJosiah W
00332bit Arm32 assembly 12 bytes250311T130616Zpetroleu
004Thumb2 assembly 8 bytes250311T130253Zpetroleu
008CASIO BASIC CASIO fx9750GIII241120T160629Zmadeforl
002Uiua241118T014835Znyxbird
005Easyfuck240322T132853ZQuadrupl
004BitCycle u180117T221832ZDLosc
017Swift231231T191038ZmacOSist
010Desmos170504T012624ZDanTheMa
008R 4.1+231230T072155Zqwr
005Gema231230T013745Zmanatwor
021Python 3231229T154155ZLarry Ba
017Commodore BASIC CBM/PET230530T153844ZShaun Be
003RegEx230530T134709ZThe Empt
024Lua230530T113245Zbluswimm
013Desmoslang230530T034621ZDadsdy
002Thunno 2230528T143232ZThe Thon
002Nekomata230528T155902Zalephalp
015Python230528T155003ZThe Empt
003Pyt230225T142133ZKip the
nan230114T134746ZThe Thon
011C gcc170504T150213ZRaycho M
060Aussie++220318T221228ZBbrk24
003Vyxal211223T191845ZLarry Ba
008APOL211215T184423ZGinger
019Python 3211214T145735ZLarry Ba
025Forte210606T000727ZDLosc
041Acc!!180117T231131ZDLosc
042C clang210605T062929ZStack Ex
062Lolwho.Cares210604T223330ZRobot
012Swift210604T214508ZEric Xue
007BRASCA210128T113021ZSjoerdPe
012Pxem210602T124738Zuser1004
082MMIX210516T003751ZNoLonger
008AWK210513T004050ZPedro Ma
002Vyxal210512T212600ZUndersla
016Python 3210128T102729ZMthd
007Sed180424T080745ZToby Spe
011Javascript210128T113404ZRohan
006convey210128T051012ZJo King
006ARM Thumb2 machine code210127T212651ZEasyasPi
002MathGolf210127T193635ZKevin Cr
024Rockstar200928T103618ZShaggy
006Labyrinth200928T002740ZBubbler
020MAWP200812T064045ZRazetime
004Keg191230T123624Zuser8505
012Flurry200812T053540ZBubbler
2125Binary Lambda Calculus200126T205035ZItai Bar
003GolfScript200126T095112ZLCU00
070naz200126T070737Zsporebal
002W191230T122941Zuser8505
006Triangular190917T180658Zsquid
013Zsh190327T113001ZGammaFun
002Gaia190327T140629ZGiuseppe
00205AB1E190327T103515ZKevin Cr
nanSinclair ZX81/Timex TS1000/1500 BASIC ~19 tokenized BASIC bytes180104T100724ZShaun Be
005Gol><>180415T061948ZBubbler
010JavaScript Node.js180413T085859ZMuhammad
009Java 8180413T091322ZKevin Cr
006><>180412T211514ZSE - sto
041Whitespace180413T084655ZKevin Cr
008QBIC170502T192543Zsteenber
014tinylisp180117T235210ZDLosc
4936SNOBOL4 CSNOBOL4171215T184044ZGiuseppe
009GCC command line171220T052931Zl4m2
010Julia 0.6180117T173516Zgggg
2018Chip170509T225649ZPhlarx
017PowerShell170502T165819Zcolsw
013Excel VBA170614T202419ZTaylor R
008Aceto170509T235021ZL3viatha
016R170614T182329ZShayne03
026JS ES5170510T123014ZDN00B
021Python 21 Bytes170510T041247Ztgabb
043Bash180104T080638ZNTCG
009Clean180104T103954ZΟurous
011Ruby180104T101145ZG B
007Implicit171226T223854ZMD XF
006J171227T094733ZBolce Bu
009Google Sheets171227T000107ZTaylor R
005x86 opcode171218T204427Zl4m2
004Pushy171217T121816ZFlipTack
006Befunge171218T150010ZJo King
027Rust171218T144246ZHåv
011Symbolic Python171217T123206ZFlipTack
008Braingolf170503T145429ZMayube
008Element170805T191846ZaAaa aAa
002170805T170820Ztotallyh
002Husk170801T200220Zბიმო
013R170502T175333ZGiuseppe
007Groovy170801T211906ZMagic Oc
021TSQL170614T183104ZBradC
012Julia170510T010227Zeaglgene
017Excel VBA170506T115447ZStupid_I
013Ruby170504T165618Zanna328p
010Clojure170504T135418Zgacelita
013R170504T104447ZSven Hoh
303Arnold C170504T071934Zegonr
009x8664 Assembly170503T154125ZCody Gra
009Groovy170503T235554ZJohannes
004Charcoal170503T222306ZASCII-on
010BrainFlak170502T164000ZDJMcMayh
025Swift170503T210431ZCaleb Kl
nanPerl 5170502T182116ZCraigR88
517Taxi170502T201934ZEngineer
012Clojure170502T173526Zmark
014Starry170502T231020ZLuis Men
011C#170503T092530ZTheLetha
020SpecBAS170503T093046ZBrian
010Java 8170502T165739ZLinnea G
010Excel170503T084444Zpajonk
019JavaScript170503T064924ZNurrl
022C++170503T062244Zjdt
042Silberjoder170503T041541Zquintopi
010ClojureScript170503T032954Zmadstap
005CJam170502T214612ZEsolangi
002Japt170503T015347ZOliver
005Befunge98170503T004939ZMercyBea
040Beam170503T000215ZMickyT
012Ruby170502T222543ZValue In
029Java170502T212604ZKhaled.K
062Perl 5170502T210956ZChris
002k170502T203010Zzgrep
006Ohm170502T170927ZLinnea G
005Haskell170502T194703Znimi
038Whirl170502T194505ZEngineer
010Excel170502T194449Zqoou
014BrainFlak170502T190944ZMegaTom
012BinaryEncoded Golfical170502T173455ZSuperJed
00705AB1E170502T185522Zosuka_
317Universal lambda170502T184016Zjimmy230
007dc170502T182853ZDigital
006Cubix170502T174838ZETHprodu
012MarioLANG170502T175742ZBusiness
002Japt170502T162923ZETHprodu
004braingasm170502T174555Zdaniero
002Jelly170502T173759Zuser6213
011dc170502T173217Zdaniero
011PHP170502T172155ZJör
015Python170502T171617Zdaniero
003APL Dyalog170502T164058Zuser4180
004Microscript II170502T171419ZSuperJed
010AWK170502T171233ZRobert B
002J170502T171221ZAdá
011///170502T170806Zsporkl
003Math++170502T170742ZSuperJed
076Hexagony170502T165703ZFryAmThe
017Batch170502T165745ZNeil
008JavaScript ES6170502T165302ZShaggy
013C gcc170502T164100ZSteadybo
003Brachylog170502T164856ZFatalize
005CJam170502T164808ZLuis Men
004V170502T164730ZDJMcMayh
005V170502T163641Zuser4180
003MATL170502T164532ZLuis Men
008Mathematica170502T164248Zuser6198
002Oasis170502T164317ZAdnan
007TIBASIC170502T164250ZScott Mi
007JavaScript ES6170502T164206ZArnauld
002Jelly170502T164200Zuser4854
027C170502T164109Zcleblanc
004Retina170502T163730ZMartin E
007Alice170502T163542ZMartin E
002Pyth170502T163459Zuser4854

Uiua, 2 bytes

↥1

No need for explanation but here's one:

↥1 => determine maximum between n and 1

Try this online!

Raku (Perl 6) (rakudo), 7 bytes

{$_||1}

Attempt This Online!

SAKO, 30 bytes

PODPROGRAM:D(N)
D()=N+0*N
WROC

Uses a specification in SAKO that 0*0 = 1.

Full programme version, 41 bytes

1)CZYTAJ:N
DRUKUJ(9,0):N+0*N
STOP1
KONIEC

BrainChild ASM, 6 bytes

asm function f(int)->int{
    xpopa
    cpyab
    notb
    addba
    xpusha
    ret
}

Adds the top of the X Stack to the logical not of it, which would be 1 for 0 and 0 for anything else.

Hex-dump of bytecode

           0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
00000000: 34 04 26 1C 2E 14                               | 4.&...          

Try It Online!

BrainChild, 11 bytes

int s=>s||1

Try It Online!

Piet + ascii-piet, 6 bytes (1×6=6 codels)

msvcas

Try Piet online!

Piet visualisation of the ascii-piet image defined above.

Surprisingly simple:

  1. Read number
  2. Duplicate
  3. Not
  4. Add
  5. Print number

Does not terminate, a terminating version would be msvcaS ss for 6 additional bytes and codels.

Tcl, 24 bytes

puts [expr max($argv,1)]

Try it online!


Alternative approach, same size:

Tcl, 24 bytes

puts [expr $argv^!$argv]

Try it online!

brainfuck, 8 bytes

+>,[>]<.

Try it online!

Bespoke, 49 bytes

doing a no-zero question
a solution:flip,adding N

Adds the inputted number to the result of doing STACKTOP F on it. STACKTOP F results in 1 if the number is zero, and 0 otherwise, essentially "flipping" it.

32-bit Arm32 assembly; 12 bytes, 3 instructions

f:
    cmp r0, 0        // 0xE3500000
    add.eq r0, r0, 1 // 0x02800001
    bx lr            // 0xE12FFF1E

Each instruction is 4 bytes long. Like my other answer, it works like as if it were extern int f(int);, and handles 32-bit integers.

Thumb-2 assembly; 8 bytes, 4 insns

f:
    cmp r0, 0       // 0x2800
    it eq           // 0xbf08
    adds r0, r0, 1  // 0x1c40
    bx lr           // 0x4770

Each instruction is 2 bytes long. It follows a normal calling convention and can be called from regular C code as if it were extern int f(int);

Since Thumb doesn't have predicated instruction encodings inside individual instructions, it instead relies on the if-then it instruction.

This code can handle any 32-bit integer.

CASIO BASIC (CASIO fx-9750GIII), 8 bytes

?→A
A+Not A

Uiua, 2 bytes

↥1

Try it!

The ↥ maximum with 1.

Easyfuck, 5 bytes

Solution:

+$":'

Explanation:

+ increments the cell at the pointer
$ copies cell at the pointer into storage
" takes in an 8 bit integer
: puts max(current cell, storage) into the current cell
' outputs an 8 bit integer

BitCycle -u, 8 7 4 bytes

-1 byte thanks to Jo King

?/1!

Try it here!

How it works

The -u flag converts decimal inputs to unary and unary outputs to decimal. Inputs emerge from the source ? moving east.

Swift, 19 18 17 bytes

var f={max(1,$0)}

Taking advantage of the "non-negative" rule here.

Desmos, 10 bytes

Improvement suggested by Aiden Chow.

f(x)=0^x+x

Previous 13-byte solution:

f(x)=max(1,x)

Try it here

R 4.1+, 8 bytes

\(n)n+!n

Attempt This Online!

Gema, 5 characters

\A0=1

Sample run:

bash-5.2$ gema '\A0=1' <<< '0'
1

bash-5.2$ gema '\A0=1' <<< '10'
10

Try it online! / Try all test cases online!

Python 3, 21 bytes

lambda n:{n:n,0:1}[n]

Try it online!

Also note that {0:1,n:n} doesn't work because if n is 0 the n:n overrides 0:1

Commodore BASIC (CBM/PET, VIC-20, Commodore C64, Commodore C16/+4) 19 BASIC tokens, 17 PETSCII characters with keyword abbreviations

0INPUTN:?N+-(N=.)

Very simple, in Commodore [early Microsoft] BASIC, if you do like PRINT X=Y it will return -1 if true, or 0 if false. A single equals is used for comparison and assignment, and the context is picked up by the interpreter.

We ask for a number with the INPUT keyword, which will enter a numeric value into the variable N. So we will then PRINT N plus a negative of the returned value of N=. with the . being a more performant replacement for 0 in this instance (a very trivial optimisation for such a short program). When N is 0, it adds --1, which just adds 1. When it is not zero, then we add -0 which is zero.

Stay Away from Zero on the CBM PET

RegEx, 3 Bytes

Match pattern (2 Bytes):

^0

Substitution pattern (1 Byte):

1

Takes input as string without any leading zeros and substitutes it for 1 if it is 0.

Try on Regex101

Lua, 24 bytes

print(0<0+...and...or 1)

Try it online!

Desmoslang, 14 13 Bytes

IS+1-\sgn(DOT

Old:

ISE\{D=0,D\}OT

Thunno 2, 2 bytes

1|

Attempt This Online! Logical OR with 1.

Alternative:

Attempt This Online! Maximum of input and 1.

Nekomata, 2 bytes

1M

Attempt This Online!

Max with 1.

Python, 15 Bytes

lambda x:x or 1

Thanks for choosing a falsey value to avoid!

Try it online!

Pyt, 3 bytes

1←↑

Try it online!

1       push 1
 ←      get input
  ↑     get maximum value on the stack; implicit print

Thunno, \$ 2 \log_{256}(96) \approx \$ 1.65 bytes

1~

Attempt This Online!

Explanation: logical OR (~) with 1.

C (gcc), 11 bytes

f(n){n?:1;}

Try it online

Aussie++, 60 bytes

THE HARD YAKKA FOR f IS(x)<YA RECKON x ==0?<BAIL 1;>BAIL x;>

All whitespace is mandatory. Tested in commit 9522366, where all numbers are truthy (see this issue), so I can't just say BAIL x ||1;.

Vyxal, 3 bytes

¬[1

Try it Online!

Explanation:

# implict input
 ¬  # logical not
  [1  # 1 if truthy else the original input
# implict output

APOL, 8 bytes

¿(⧣ ⋔ 1)

Explanation

¿(   Returning if statement
  ⧣    Integer input (condition, 0 evaluates to false)
  ⋔    If item (returns the value of the condition, executed if true)
  1    A literal 1 (executed if false)
)
Implicit print

Python 3, 19 bytes

lambda n:[n,1][n<1]

Try it online!

Forte, 25 bytes

9LET0=1:INPUT2:PRINT2:END

Try it online!

Explanation

Clearly, the best way to approach this challenge is to define 0 to be 1. Problem solved.

Seriously. That's exactly what this program does.

9          Line number (doesn't matter as long as it's not 0 or 2)
 LET 0=1   Redefine 0 to be 1; all future occurrences of 0 will evaluate as 1
 INPUT 2   Redefine 2 to be a number read from input; all future occurrences of 2 will
           evaluate as the input number, though of course if that number was 0 it
           actually evaluates as 1
 PRINT 2   Print that number
 END       End the program

Acc!!, 75 72 41 bytes

N
_+48/_
Count i while _/48 {
Write _
N
}

Try it online!

Explanation

N reads a character and stores its ASCII code into the accumulator.

Since the first character will always be a digit, the accumulator's value is between 48 and 57. If the accumulator is exactly 48, 48/_ will be 1; otherwise, it will be 0. We add this value to the accumulator. In effect: if the first digit of the number was 0, we consider it as 1; otherwise, we leave it unchanged.

We then enter a loop that writes the accumulator out as a character, reads another character into the accumulator, and loops until the ASCII code we read is less than 48 (probably 10 for newline). Then we halt.

C (clang), 63 42 bytes

main(i){scanf("%i",&i);printf("%i",i?:1);}

Try it online!

Much readable than C answers that already exists here. An if-else statement whether to output 1 or the other.

Thanks to ceilingcat for golfing 21 bytes.

Lolwho.Cares, 62 bytes

*2*+21*1*+21010,**>*2+00210`v
0 ^02210012+*1*<  ^<0210002<<
321

Old version:

*2*+210*1*+210101,**>*2+00210`v
0 ^ 102210012+*1*<  ^<0210002<<
253

The last line isn't code; it's the input number.

Online interpreter: https://valthe.scheffers.net/testing/lolwhocares

Swift, 12 bytes

Types provided, 12 bytes

{$0==0?1:$0}
{
  $0 == 0 ? 1 : $0
}

Types not provided, 20 bytes

{(n:Int)in n==0?1:n}

```swift
{ (number: Int) -> Int in
  number == 0 ? 1 : number
}

BRASCA, 14 7 bytes

ig:0=+n

Try it online

-7 bytes by RezNesX

Explanation

<implicit input> - Push STDIN to stack
ig               - Convert numbers from ASCII to number, and concatenate the stack
  :0=            - If the number is zero (pushes 1)
     +n          - Add and print as number.

```

Pxem, 12 bytes (content).

Unprintable characters are escaped.

.c\001.y.s\001.d.a

Usage

Usage example

Filename to be _.e.n, with your input from stdin.

MMIX, 8 bytes (2 instrs)

(jxd)

00000000: 6300 0001 f801 0000                      c¡¡¢ẏ¢¡¡

(assembly)

foo CSZ $0,$0,1
    POP 1,0

Honestly, this function really should be inlined. It costs three instructions to call, but just one to inline.

AWK, 8 bytes

$0||$0=1

Try it online!

Slightly different approach to this answer, reducing 2 bytes.

$0||$0=1      Basically, an OR logic gate. Right part is not considered if the left one is true.
              $0 is the input, parsed as true if different from zero, printing the input.
              If input is zero, $0 is set to 1 (right part).
              As $0 becomes 1, it is parsed true, and then the input is printed.

Vyxal, 2 bytes

¬+

Straightforward answer:

¬  # nots the input (x == 0 ? 1 : 0)
+  # adds it to the input

Try it Online!

Python 3, 16 bytes

lambda x:x+(x<1)

Try it online!

Thanks caird coinheringaahing for saving an extra byte!

Sed, 7 bytes

Input in any number base, without any leading zeros. (It doesn't even need to be a consistent base!)

s/^0/1/

0 is the only number that begins with 0; just change that to 1.

Javascript, 8 11 bytes

Probably a bad implementation, but here:

n=>n==0?1:n

Explanation:

n // The input
n == 0 // Checks whether n is zero
?1 // If so, return 1.
:n // However, if n isn't zero, then return n

convey, 6 bytes

{+1
}.

Try it online!

Outputs the max of the input and 1. I think this is the optimal answer, since to use any binary function, there must be a second line with at least two characters.

You can also do the more traditional x+!x for 8 bytes.

ARM Thumb-2 machine code, 6 bytes

Machine code:

b900 3001 4770

Assembly:

        .syntax unified
        .arch armv6t2
        .thumb
        .globl no_zero
        .thumb_func
no_zero:
        // skip next insn if r0 != 0
        cbnz    r0, .Ldont_add_1
.Ladd_1:
        // increment r0
        adds    r0, #1
.Ldont_add_1:
        // Return
        bx      lr

It doesn't get much simpler than that.

Input is in r0, output is in r0, follows standard calling convention.

ARM Thumb-2 machine code, branch/IT-less, 8 bytes

Only works for non-negative numbers unlike the branching solution.

Machine code:

4241 f140 0000 4770

Assembly:

        .syntax unified
        .arch armv6t2
        .thumb
        .globl no_zero_branchless
        .thumb_func
no_zero_branchless:
        // Negate r0 into r1. We only care about
        // setting the flags here.
        negs    r1, r0
        // Add the carry flag to r0. (wide insn)
        adc     r0, r0, #0
        // Return
        bx      lr

Follows the same calling convention.

negs follows the same rules as subs for setting flags. So, if r0 was positive, the result would have a borrow, but if it was 0, it would not.

Then, we just add with carry against zero to add 1 if r0 was zero, or 0 if r0 was positive.

Yes, you read that correctly.

When subtracting, ARM clears the carry flag to indicate a borrow. It is counterintuitive and usually annoying when golfing.

But I decided to use this for a small challenge.

Unfortunately, adc doesn't have a narrow immediate form, so we either have to waste another register to set it to zero, or use a wide instruction.

MathGolf, 2 bytes

┌+

Try it online.

Explanation:

┌   # Inverted boolean the (implicit) input-integer (1 if 0; 0 for any other integer)
 +  # Add this to the (implicit) input-integer
    # (after which the entire stack joined together is output implicitly as result)

Rockstar, 24 bytes

listen to N
say N-0 or 1

Try it here (Code will need to be pasted in)

Labyrinth, 6 bytes

?"1
@!

Try it online!

?   Take number input and push it
"   No-op, but a 3-way junction:
    If top is 0, go straight
1     Convert the 0 to 1 and bounce off the dead end
"     Enter the junction again, turn right (reflected to south)
!@    Pop and print as number, turn around the corner and halt

    Otherwise, top is positive; turn right
!@    Pop and print as number and halt

MAWP, 4 20 bytes

%@_1A[1A~25WWM~]~?1:

Responds to numbers which have more than 1 digit.

Try it!

Keg, -hr 4 bytes

:0=+

Try it online!

Explanation

:     # Take 2 inputs
  0=  # Check whether the input is 0
      # (Yields 1 if the input is 0)
      # (Yields 0 otherwise)
    + # Add the input with this result and print it rawly
      # i.e. 0->1, 5->5

Flurry, 12 bytes

({})[(){}]{}

Run example

$ ./flurry -nin -c "({})[(){}]{}" 0
1
$ ./flurry -nin -c "({})[(){}]{}" 1
1
$ ./flurry -nin -c "({})[(){}]{}" 2
2
$ ./flurry -nin -c "({})[(){}]{}" 10
10

For single input n, computes n (K n) 1: apply "a constant function that returns n regardless of argument" n times to the number 1.

({})    Pop n and push n
[(){}]  Apply (K n); n is popped again from the stack
{}      Apply I (equivalent to number 1); popping from empty stack gives I

Reduction into SKI terms don't help much:

n (K n) 1
= I n (K n) 1
= S I K n 1
which translates into <>{{}}(){}{}

Binary Lambda Calculus, 2.125 Bytes

00010110 00110001 0

Translation into lambda calculus:

\n. n (\x. n) (\x. x)

GolfScript, 4 3* bytes

~1|

Try it Online!

*thanks to user a'_'

naz, 70 bytes

2a2x1v4a8m2x2v1x1f1r3x2v2e1o3f0x1x2f1a1o0x1x3f1r3x1v4e1o3f0x1x4f0a0x1f

Works for any input integer, provided it's passed as a file terminated with the control character STX (U+0002).

Explanation (with 0x commands removed)

2a2x1v           # Set variable 1 equal to 2
4a8m2x2v         # Set variable 2 equal to 48 ("0")
1x1f1r3x2v2e1o3f # Function 1
                 # Read a byte of input
                 # Jump to function 2 if it equals variable 2
                 # Otherwise, output it and jump to function 3
1x2f1a1o         # Function 2
                 # Add 1 to the register and output
1x3f1r3x1v4e1o3f # Function 3
                 # Read a byte of input
                 # Jump to function 4 if it equals variable 1
                 # Otherwise, output it and jump back to the start of function 3
1x4f0a           # Function 4
                 # Add 0 to the register
1f               # Call function 1

W, 2 bytes

1|

Explanation

a   # Take an input
 1| # Logical or with 1
    # If n is 0, this evaluates to 1
    # It evaluates to 0 otherwise

Triangular, 6 bytes

$,w%1<

Try it online!

Ungolfed:

  $
 , w
% 1 <
-----------------------
$              Read from input as an integer
 w,            Change directions if ToS != 0 (will go straight to print)
   <1          Push 1
     %         Print ToS as an integer

Zsh, 13 bytes

<<<$[$1?$1:1]

Try it online!

Bash, 15 bytes

echo $[$1?$1:1]

Try it online!

Dash (or other POSIX-compliant shell), 17 bytes

echo $(($1?$1:1))

Try it online!

Gaia, 2 bytes

1Ṁ

Try it online!

Takes the ax of 1 and the input.

05AB1E, 2 bytes

_+

Try it online or verify some more test cases.

2 bytes alternative by @Adnan:

$M

Try it online or verify some more test cases.

Explanation:

_   # Check if the (implicit) input is 0 (0 becomes 1; everything else becomes 0)
 +  # Add it to the (implicit) input (0 becomes 1; everything else stays the same)
    # (and output the result implicitly)

$   # Push both 1 and the input to the stack
 M  # Push the largest number of the stack (without changing the rest of the stack)
    # (and output the top of the stack implicitly as result)

Sinclair ZX81/Timex TS1000/1500 BASIC ~19 tokenized BASIC bytes

 1 INPUT A
 2 PRINT A+NOT A

This is a more efficient solution than the one below; essentially it takes the NOT value of A (which would be zero in all cases but zero) and adds that to the value of A.

Old answer:

Sinclair ZX81/Timex TS1000/1500 BASIC, ~31 tokenized BASIC bytes

 1 INPUT A
 2 IF NOT A THEN LET A=NOT A
 3 PRINT A

This takes a numeric input from the user and will display 1 if zero is entered by making A NOT A; otherwise it does nothing and displays the numeric value.

Gol><>, 5 bytes

I:z+h

Try it online!

Given n, calculate n + !n, print as int and halt. Unfortunately Gol><> doesn't have implicit input option, so the bytes are the same as regular ><>.

JavaScript (Node.js), 10 bytes

n=>n&&n||1

Try it online!

here is one more

JavaScript (Node.js), 8 bytes

n=>n?n:1

Try it online!

and lastly

JavaScript (Node.js), 7 bytes

n=>n||1

Try it online!

Java 8, 9 bytes

n->n|1>>n

Try it online.

C# .NET, 9 bytes

n=>n|1>>n

Try it online.

Different approach (and 1 byte shorter) than the existing Java/C# .NET answers. (Also works with negative inputs.)

Explanation:

i->       // Method with integer as both parameter and return-type
  i|      //  Return the input bit-wise OR-ed with:
    1>>i  //  1 bit-wise right-shifted by the input

1>>i will be 1 when the input is 0, and 0 for every other input.
0|1 for input 0 will therefore result in 1, and n|0 for every other input will therefore result in n.

><>, 6 bytes

:?!1n;

Could have been 1 byte shorter if ? had the opposite conditional behaviour.

:?       check if nonzero, then either
  !      a) skip the next instruction or
   1     b) push 1 to the stack
    n    print
     ;   terminate

Whitespace, 41 bytes

[S S S N
_Push_0][S N
S _Duplicate][T N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve][S N
S _Duplicate_input][N
T   S N
_If_0_jump_to_Label_0][T    N
S T _Print_as_integer][N
N
N
_Exit][N
S S N
_Create_Label_0][S S S T    N
_Push_1][T  N
S T Print_as_integer]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Explanation in pseudo-code:

Integer i = STDIN as integer
If i == 0:
  Call function Label_0
Print i
Exit program

function Label_0:
  Print 1
  Exit implicitly with error: Exit not defined

Example runs:

Input: 0

Command    Explanation              Stack    Heap     STDIN    STDOUT    STDERR

SSSN       Push 0                   [0]
SNS        Duplicate top (0)        [0,0]
TNTT       Read STDIN as integer    [0]      {0:0}    0
TTT        Retrieve                 [0]      {0:0}
SNS        Duplicate top (0)        [0,0]    {0:0}
NTSN       If 0: Jump to Label_0    [0]      {0:0}
NSSN       Create Label_0           [0]      {0:0}
SSSTN      Push 1                   [0,1]    {0:0}
TNST       Print as integer         [0]      {0:0}             1
                                                                         error

Try it online (with raw spaces, tabs and new-lines only).
Stops with error: Exit not defined.

Example runs:

Input: 5

Command    Explanation              Stack    Heap     STDIN    STDOUT    STDERR

SSSN       Push 0                   [0]
SNS        Duplicate top (0)        [0,0]
TNTT       Read STDIN as integer    [0]      {0:5}    5
TTT        Retrieve                 [5]      {0:5}
SNS        Duplicate top (5)        [5,5]    {0:5}
NTSN       If 0: Jump to Label_0    [5]      {0:5}
TNST       Print as integer         []       {0:5}             5
NNN        Exit program             []       {0:5}

Try it online (with raw spaces, tabs and new-lines only).

QBIC, 11 8 bytes

?:-(a>1)

Thanks to @l4m2 for saving me some bytes!

Explanation:

?         PRINT
 :        an integer taken from the cmd line (and store it as 'a')
  -       minus
   (a<1)  -1 if 'a' is less than 1 (can only be 0) or 0 otherwise.
          This leaves any a to be a, but turns zeroes into 1 by double negative.

Old code, that didn't use the inline : yet:

:?(a>0)+a+1

Explanation

:       Get an int from the cmd line, a
?       PRINT
 (a>0)    if a is greater than 0, this is -1, else 0
 +a        yields 0 for 0 and a-1 for >0
 +1        makes 1's for 0 and a's for all other values

tinylisp, 14 bytes

(q((n)(i n n 1

This is a lambda function. In order to be able to call it, you either need to give it a name using d or call it directly (which would require explicitly closing the parentheses before specifying the argument). Try it online!

The function takes one argument, n. If n is truthy (all positive integers), return n. Otherwise (zero), return 1.

SNOBOL4 (CSNOBOL4), 49 47 36 bytes

	N =INPUT
	N =EQ(N) 1
	OUTPUT =N
END

Try it online!

GCC command line, 9 bytes

-Df(x)x?:

Try it online!

-D in GCC checks if the following content has an =; if not, it add the code

#define <followed_content> 1

which in this case turns into

#define f(x)x?: 1

Julia 0.6, 10 bytes

x->x<1?1:x

Try it online!

Chip, 20 18 bytes

eaABb
*`\\-!
fcCDd

Try it online!

How?

 aABb
            Copy the low 4 bits from input to output
 cCDd

e
*           Set the higher bits of output, so that the values are ASCII digits
f

eaABb
*           Replicate any ASCII digits on input to output
fcCDd

            -
     !      Produce a high signal, but only during the first byte
            -

 aAB
 `\\-*      Set the lowest bit of output, if the four low bits of input are unset
  CD

 aAB        Set the lowest bit of output, if the four low bits
 `\\-!      of input are unset, and only on the first byte
  CD

PowerShell, 24 22 17 Bytes

blatantly stolen from here

!($a=$args[0])+$a

Explanation

Invert the value, returning 0 for non-0 numbers, and 1 for 0, then add the intitial to it.

this makes it basically 1/0 + value, so for 0 the first value is 1, any other numbers it's 0.

examples:
# !0+0 = 1
# !1+1 = 1
# !9+9 = 9

Excel VBA, 17 13 Bytes

Anonymous VBE Immediate function that takes input as expected type unsigned integer and then outputs to the VBE immediate window

?[Max(A1,1)]

Previous Version

?[If(A1,A1,1)]

Aceto, 9 8 bytes

rid0=`1p

read an integer and duplicate it, then push 0. Are they =? Then (`) push a 1. print the top element.

R 20 16 bytes

pryr::f(n+(n<1))

JS ES5, 26 bytes

function (n){return n?n:1}

Python 21 Bytes

int(max('1',input()))

Takes input from REPL environment

Bash, 43 bytes

if [ $1 -eq 0 ];then echo 1;else echo $1;fi

Clean, 9 bytes

?0=1
?n=n

Try it online!

Ruby, 11 bytes

->n{n|1>>n}

Implicit, 7 bytes

$!{.

Try it online! Explanation:

$      read input
 !{    if falsy
   .   increment
       implicit output

J, 6 Bytes

(>.1:)

Standard solution: Return the max of 1 and the argument.

The parenthesis ensure it's evaluated as a monadic hook:

(>.1:) 0
0 >. (1: 0)    NB. Definition of a monadic hook.
0 >. 1         NB. 1: is a constant function, always returns 1.
1              NB. >. returns the max of its two arguments.

Google Sheets, 9 Bytes

Anonymous worksheet function that takes input from range A1 and outputs to the calling cell

=Max(1,A1

x86 opcode, 6 5 bytes

       41                         INC     ECX
entry: E3 FD                      JECXZ   SHORT $-1
       91                         XCHG    EAX,ECX
       C3                         RETN

ECX -> EAX

Pushy, 4 bytes

&n+#

Try it online!

   #  \ print:
  +   \   input + ...
&n    \   not(input)

Befunge, 6 Bytes

&:!+.@

Try it Online

& Gets input as number
  :! Duplicates and inverts
    +.@ Adds the inverted input to the original, prints and ends the program

Rust, 27 bytes

|x:u64|if x==0{1}else{x};

Anonymous function, or lambda, taking input from x.

First time golfing with Rust, and i must say im quite impressed.

Symbolic Python, 11 bytes

_+=_==(_>_)

Try it online!

_+=           # Output = Input +
   _==(_>_)                       Input == 0

Braingolf, 8 bytes

!?_:1_;

Explanation:

 ?       If last element on stack > 0
!        Prevent if check from consuming last element on stack
  _      Pop last element on stack and print
   :     Else
    1    Add int literal 1 to end of stack
     _   Pop last element on stack and print
      ;  Prevent automatic pop of last element on stack

Element, 8 bytes

_2:'!"+`

Try it online

,,,, 2 bytes

1∨

Try it online!

,,, is on TIO now, so that's cool. Computes input or 1 (logical OR) and implicitly outputs the result.

Husk, 3 2 bytes

|1

Try it online!

Ungolfed/Explanation

    -- implicit input N
|   -- if N is truthy: N
 1  -- else (N==0): 1

Thanks @Zgarb for -1 byte!

R, 13 bytes

max(1,scan())

reads n from stdin. With pmax, it can read in a list and return the appropriate value for each element in the list for +1 byte.

try it online!

I should note that there is another fine R solution in 13 bytes by Sven Hohenstein which allows for yet another 13 byte solution of

(n=scan())+!n

which makes me wonder if that's the lower limit for R.

Groovy, 7 bytes

{it?:1}

Elvis operator; if true, return self, else return 1. Only false integer value auto-unboxxed to false in Groovy is 0. Thusly, exactly the spec.

T-SQL, 21 bytes

SELECT MAX(1,a)FROM t

SQL input is allowed via a pre-existing named table (table t with INT field a).

Julia, 13 12 bytes

f(n)=n<1?1:n

Unfortunately, Julia doesn't do implicit casting from int to bool, so I have to burn an entire 3 characters just to do a comparison to zero. Saved one byte by safely assuming the number isn't negative. Still too verbose for my taste, though.

Excel VBA 17 bytes

[a1]=IIF(n=0,1,n)

Simple if else statement you can run it from vba immediate window

Ruby, 13 bytes

->i{i==0?1:i}

Clojure, 10 bytes

#(max 1%)

Not much to explain.

R, 13 bytes

n=scan();n+!n

Here, scan is used to read the input value n. The negation of n (i.e., !n, 0 or 1) is added to n.

Arnold C, 303 bytes

IT'S SHOWTIME
HEY CHRISTMAS TREE i
YOU SET US UP 1
GET YOUR ASS TO MARS i
DO IT NOW
I WANT TO ASK YOU A BUNCH OF QUESTIONS AND I WANT TO HAVE THEM ANSWERED IMMEDIATELY
BECAUSE I'M GOING TO SAY PLEASE i
TALK TO THE HAND i
BULLSHIT
TALK TO THE HAND 1
YOU HAVE NO RESPECT FOR LOGIC
YOU HAVE BEEN TERMINATED

Trying to explain it:

IT'S SHOWTIME //main()
HEY CHRISTMAS TREE i //int i
YOU SET US UP 1 //i = 1
GET YOUR ASS TO MARS i // ? compiler told me to add that
DO IT NOW // ? compiler told me to add that
I WANT TO ASK YOU A BUNCH OF QUESTIONS AND I WANT TO HAVE THEM ANSWERED IMMEDIATELY // something related to reading from stdin
BECAUSE I'M GOING TO SAY PLEASE i // if(i)
TALK TO THE HAND i //print i
BULLSHIT //else
TALK TO THE HAND 1 //print 1
YOU HAVE NO RESPECT FOR LOGIC //endif
YOU HAVE BEEN TERMINATED //end main()

It even beats this answer!

x86-64 Assembly, 10 9 bytes

Following the standard System V AMD64 calling convention, this function accepts a 32-bit unsigned integer parameter via the EDI register, and returns the result via the EAX register:

89 F8  |     mov   eax, edi    ; move parameter from EDI to EAX
85 C0  |     test  eax, eax    ; test input and set flags
75 01  |     jnz   Finished    ; if input is non-zero, then jump to end
FF 40  |     inc   eax         ; otherwise, input is 0, so increment it to 1
       |  Finished:
C3     |     ret               ; return, leaving result in EAX

x86-32 Assembly, 8 bytes

We could also write this as 32-bit code, since we're only dealing with 32-bit values.

The nice thing about this is that the INC instruction becomes only 1 byte in length. (In 32-bit mode, inc eax can be encoded simply as 40. In 64-bit mode, 40 is interpreted as a REX prefix, so the leading FF is needed. See Intel's documentation for this instruction.)

The caveat is that most 32-bit calling conventions pass parameters on the stack, rather than in registers, and loading a value from the stack (memory) takes many more bytes. If we can be allowed a __fastcall-style calling convention that passes parameters in registers (supported by virtually all C compilers, so not really cheating, just a bit less standard), then the integer parameter is passed in ECX and we get the following code, for a total of 8 bytes:

89 C8  |     mov  eax, ecx
85 C0  |     test eax, eax
75 01  |     jnz  Finished
40     |     inc  eax
       |  Finished:
C3     |     ret

Groovy, 9 bytes

f={it?:1}

Inside a groovy script file you can run with "groovy -D n=0 ":

println System.properties.n?:1

As a closure:

f={it?:1}

1) "?:" is groovy's "elvis-operator"

One instance of where this is handy is for returning a 'sensible default' value if an expression resolves to false-ish

2) "it" refers to a single anonymous parameter the closure is called with

3) 0 evaluates to false in groovy-truth

Charcoal, 4 bytes

I∨N¹

Try it online!

Explanation

I    Cast (number is casted to string)
 ∨N¹ input number logical-or 1

Brain-Flak, 22, 10 bytes

({{}}[]{})

Try it online!

Explanation:

If the input is non-zero, then {{}} will pop everything off the stack and evaluate to the input. If it is zero, nothing will be popped, and it will evaluate to zero. So running ({{}}) gives

Non-zero:

n

Zero:

0
0

At this point, we'll add the height of the stack (0 for non-zero, 1 for zero) and pop one more value off the stack. (since the stack is padded with an infinite number of 0's, this will pop either the top 0 or an extra 0)

Swift, 25 bytes

max(1, Int(readLine()!)!)

If you just have the body of a closure, then it is just 10 bytes:

max(1, $0)

Takes in standard input and then returns the max int, which would either be 1 or higher.

Perl 5, 10 +1 byte for -p flag = 11 bytes

$_=$_*1||1

Run with -p flag.

Taxi, 517 bytes

Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:s 1 l 1 r.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 l 1 l 2 r.Pickup a passenger going to Addition Alley.Pickup a passenger going to Knots Landing.Go to Knots Landing:n 2 r 2 r 1 l.Pickup a passenger going to Addition Alley.Go to Addition Alley:w 1 r 1 l 2 l.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:n 1 r 1 r.Pickup a passenger going to Post Office.Go to Post Office:n 1 l 1 r.

Formatted for humans:

Go to Post Office:w 1 l 1 r 1 l.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery:s 1 l 1 r.
Pickup a passenger going to Cyclone.
Go to Cyclone:n 1 l 1 l 2 r.
Pickup a passenger going to Addition Alley.
Pickup a passenger going to Knots Landing.
Go to Knots Landing:n 2 r 2 r 1 l.
Pickup a passenger going to Addition Alley.
Go to Addition Alley:w 1 r 1 l 2 l.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery:n 1 r 1 r.
Pickup a passenger going to Post Office.
Go to Post Office:n 1 l 1 r.

The key location is Knots Landing which performs the NOT operation so 0 returns 1 and all other numbers return 0. Now, you can go to Addition Alley to add the result from Knots Landing to the original input.

Clojure, 12 bytes

#(get[1]% %)

The get function takes an associative data structure, a key, and a default value. Vectors are associative using sequential position as the key. So, [1] is a vector with the value 1 at position 0. If get is called with parameter 0 it will return 1, otherwise no other keys exist in the vector so it returns the default value of the parameter.

Starry, 14 bytes

, +'      +*`.

Try it online!

Explanation

Space shown as _ .

,           Read integer and push to stack
_+          Duplicate
'           If non-zero jump to branch label
______+     Push 1
*           Add
`           Mark branch label
.           Print as a number

C#, 11 bytes

n=>n<1?1:n;

This compiles to a Func<int, int>.

SpecBAS - 20 bytes

1 INPUT n: ?n OR n=0

? is shorthand for PRINT

Java 8, 10 bytes

i->i<1?1:i

Excel, 10 bytes

=MAX(A1,1)

Here's another 10-byte solution: link

JavaScript, 19 Bytes

(x)=>{return x?x:1}

Ungolefed, with example:

function f(n) {
  if(n)
    return n;
  else
    return 1;
}

f(0); // 1
f(1); // 1
f(2); // 2

C++, 22 bytes

[](int i){return!i+i;}

Try it online

Silberjoder, 42 bytes


0+b1,-CB+b1:BC<. +iB-b1+CB-CA[+CA.,-CA]1

How it works:


0

The first three characters are all data and are not executed. They are a newline (10), a zero (48), and a DC3 (19).

+b1

Point b at the "0" character. Note that a is still pointing at the newline character.

,

Read the first character of input.

-CB

Subtract what b is pointing to (the "0") from the first digit.

+b1

Point b at the DC3 character, which has value 19

:BC

Jump to position 19+3=22 if the c is pointing to anything other than zero. This would happen if the first digit of the number was anything other than "0". Otherwise...

<.

Move c on top of the "1" at the end of the program and print it.

 +iB

b is still pointing at 19, so we add 19 to the instruction pointer, jumping to the "1" at the end of the program, causing the program to halt after one more cycle. (The extra space is ignored, but we need it there to position this instruction so that the instruction pointer jumps beyond the "]" at the end of the program. If we don't do this, we will enter the loop at the end, and print an extraneous semicolon whenever 0 is input.)

-b1

This is position 22, so we jump here whenever the number didn't start with "0". We move b back to point at the "0".

+CB

Add the 48 back to the first digit of the number, restoring it to its proper character value.

-CA

Subtract the newline from the digit.

[+CA.

If it's not zero, restore it to its original value and print it.

,-CA]

Repeat reading digits, comparing them with newline, and printing them until newline is seen.

1

Data. Ignored. Program halts.

Clojure(Script), 10 bytes

#(max 1 %)

CJam, 5 bytes

ri1e|

Explanation:

ri    e# Read token and convert to integer
  1e| e# OR with 0

Japt, 2 bytes

w1

Try it online!

Returns the larger of 1 and the input.

Befunge-98, 5 bytes

&:!+.

Try it Online! (Warning - will take 60 seconds per test because of how TIO treats &)

Explanation

&:       Push 2 copies of the input
  !      Logical not the 1st copy - i.e. push 1 if 0, push 0 otherwise
   +     Add them together - this results in +0 normally, but +1 in the case of 0
    .    Print that value
         Loops back around to the first command
&        Because there's no more input, the TIO interpreter stalls for a minute and ends.

Befunge-93 Variant, 6 bytes

It's trivial to implement Befunge-93 in a similar way, except we can't use the & to end the program this time. Thus, the code is 1 byte longer, for 6 bytes:

&:!+.@

Try it Online!

Beam, 40 bytes

This reads the input as a string as it doesn't have any other option. Basically it checks if the first character is 0 by removing 48 from it. If 0 increment and output as a number, otherwise output it as a number, then read the rest of the input outputting it as characters.

 r'''''>`----\
 :+n++(------/
/<:<
r@
\u

Try it online!

Ruby, 12 bytes

->n{n<1?1:n}

Try it online!


Alternate version that reads directly from STDIN instead of being a function. Same number of bytes after counting the -p flag (11+1 = 12 bytes). Effectively a port of the Retina solution.

sub /^0/,?1

Try it online!

Java, 29 bytes

Try Online

int f(int n){return n<1?1:n;}

Perl 5, 6 + 2 bytes for the -l and -p flags

$_||=1

Takes input on separate lines from stdin. Runs with the flags -lp.

k, 2 bytes

1|

Finds the maximum of 1 and whatever number is given.

Try it online!

Ohm, 11 6 bytes

ö?┼¿1;

Uses CP-437 character encoding. Run with -c flag

Explanation:

ö?┼¿1;
       ■print(                                            )
  ┼    ■      first_input()
 ?   ; ■                   if(                     )
ö      ■                      int(first_input())!=0
   ¿   ■                                            else 
    1  ■                                                 1

Haskell, 5 bytes

max 1

Usage example: (max 1) 0 -> 1.

Nothing much to explain.

Whirl, 38 bytes

01100011100011110011111100001000111100

Try it online!

Explanation:

01100     op.ccw, op.intio    Mem1 = STDIN
011100    math.ccw, math.=    If (Mem1 = 0) Then (Math.Val = 1) Else (Math.Val = 0)
0111100   op.cw, op.one       Op.Val=1
11111100  math.add            Math.Val = Math.Val + Mem1
00        op.one              Op.Val=1 (Cheapest way to loop back to the Math wheel)
100       math.store          Mem1 = Math.Val
0111100   op.ccw, op.intio    STDOUT = Mem1

Excel, 10 Bytes

=A1+(A1=0)

This saves 4 Bytes over the obvious 'IF' statement solution, =IF(A1=0,1,A1).

Brain-Flak, 14 bytes

((){{}[()]}{})

Try it online!

Just computes: 1 + (n ? n-1 : 0).

Binary-Encoded Golfical, 12 bytes

This binary encoding can be converted back to the standard graphical representation using the encoder provided in the Golfical github repo, or run directly using the interpreter by adding the -x flag.

Hexdump of binary encoding:

00 40 02 15 17 14 00 01 23 1D 17 14

Original image:

enter image description here

Magnified 120x, with color labels:

enter image description here

05AB1E, 7 bytes

D0›i,}1

Try it online!

D           //push two inputs (implicit)
 0›         //push input greater than zero
   i        //if true
    ,}      //print input
      1     //push 1. printing is implicit if there is no previous output

Universal lambda, 3 bytes (17 bits)

00010110001100010

It is a function and not a complete program. I think it should work, but didn't actually test it because it doesn't seem easy to do so. It means λx.x(λy.x)(λy.y).

Lazy K, 10 bytes

S(SIK)(KI)

It is a function, untested, too.

dc, 7

?d0r^+p

Relies on the fact that dc evaluates 00 to 1, but 0n to 0 for all other n.

Try it online.

Cubix, 6 bytes

OI!1L@

Somehow managed to fit it on a unit cube... Test it online!

Explanation

Before being run, the code is arranged as a cube net:

  O
I ! 1 L
  @

The IP (instruction pointer) is then placed on the far-left face (I), facing to the right. The instructions run from there are:

I  Input a number from STDIN and push it to the stack.
!  If the top number is non-zero, skip the next instruction.
1  Push a 1 (only if the input was zero).
L  Turn left. The IP is now on the top face facing the !.
O  Output the top item as a number.

The IP then hits ! again, skipping the @ on the bottom face. This is not helpful, as we need to hit the @ to end the program. The IP hits the L again and goes through the middle line in reverse (L1!I) before ending up on the L one more time, which finally turns the IP onto @.

MarioLANG, 12 bytes

;
=[
:<+
 =:

Try it online!

How it works

Mario starts in the top left, initially walking right. He reads an int from input (;) and stores it in the current memory cell. Then he falls off the ground (=), hitting [, which makes him ignore the next command if the current cell is 0.

If the cell is not 0, he'll start walking left (<), output the current cell as an int (:), and fall to his death (end of program).

If the cell is 0, he ignores the command to turn left, and keeps walking right. He increments the current cell (+), outputs it, and falls to his death.

Japt, 2 bytes

ª1

Try it online!

Explanation

ª is a shortcut for JS's || operator. Japt has implicit input, so this program calculates input||1, and the result is implicitly sent to STDOUT.

w1 would work as well, taking the maximum of the input and 1.

braingasm, 4 bytes

;z+:

; reads a number from stdin, z+ increments that number if it is 0, : prints.

Jelly, 2 bytes

o1

Try it online!

An alternative to the other Jelly solution. o provides a default value for a zero/empty argument; in this case, we default it to 1.

dc, 11 bytes

[1]sf?d0=fp

[1]sf stores a macro in register f which pushes 1 to the top of the stack, ? reads input, d0=f runs macro f if input was 0, p prints the top of the stack.

Test:

$ dc -e "[1]sf?d0=fp" <<< 0
1
$ dc -e "[1]sf?d0=fp" <<< 1
1
$ dc -e "[1]sf?d0=fp" <<< 42
42

PHP, 11 Bytes

<?=$argn?:1;

Online Version

Python, 15 bytes

lambda n:n or 1

APL (Dyalog), 3 bytes

1∘⌈

Try it online!

This takes the ceil of the argument and 1.

Microscript II, 4 bytes

1sN|

Rough translation:

x=1
push x
x=readnum()
x|=pop()

x is then printed implicitly at the end.

AWK, 10 bytes

!$0{$0=1}1

Try it online!

Example Usage:

awk '!$0{$0=1}1' <<< 978

J, 2 bytes

^*

Try it online!

^ [argument] raised to the power of

* the sign of the argument (0 if 0 else 1)

Because 1=0^0 in J.

///, 11 bytes

/#0/1//#//#

Try it online!

Since there is no other way to take input in ///, hard-code the input after the last #.

Works by replacing #0 with 1. Then it removes any remaining #. The # makes sure that an input of 10 would not output 11.

Version that takes input in Itflabtijtslwi:

GGaGGGGbGG/#0/1//#//#ab

Try it online!

Math++, 3 bytes

?|1

("Body must be at least 30 characters")

Hexagony, 7 6 bytes

)?<@.!

Expanded:

 ) ?
< @ .
 ! .

Try it online!

Saved 1 byte thanks to Martin!

If the number is nonzero print it, otherwise add one to it and print that instead.

Batch, 17 bytes

@cmd/cset/a%1+!%1

JavaScript (ES6), 8 bytes

Beaten to the shortest solution (as usual!), so here's an alternative.

n=>n?n:1

Try It

f=
n=>n?n:1
console.log(f(0))
console.log(f(1))
console.log(f(8888))

C (gcc), 14 13 bytes

f(n){n=n?:1;}

Thanks to @betseg for reminding me of the n?:1 trick in the comments of the other C answer!

Try it online!

C, 17 bytes

f(n){return!n+n;}

Try it online!

C, 16 bytes

#define f(n)!n+n

Try it online!

Brachylog, 3 bytes

∅1|

Try it online!

Explanation

If we add the implicit ? (Input) and . (Output), we have:

?∅          Input is empty (that is, [] or "" or 0 or 0.0)
  1.        Output = 1
    |       Else
     ?.     Input = Output

CJam, 5 bytes

ri1e>

Try it online!

Explanation

ri   e# Read input as an integer
1    e# Push 1
e>   e# Maximum. Implictly display

V, 4 bytes

é0À

Try it online!

Abuses an non-preferred but expected behavior, so I can't really call it a bug. Explanation:

In Vim, commands accept a count. For example, <C-a> will increment a number, but 7<C-a> will increment a number by 7. However, you can't use 0 as a count, because

This is fine for a text editor, but usually obnoxious for a golfing language, so V overwrites some commands so that 0 is a valid count. For example, é, ñ, Ä, and some others. However, since <C-a> is a builtin vim command, it is not overwritten, so running this with a positive input gives:

N       " N times:
 <C-a>  "   Increment

But running with 0 as input gives:

0       " Go to column one
 <C-a>  " Increment

Full explanation:

é0          " Insert a 0
  À         " Arg1 or 1 times:
   <C-a>    " Increment

V, 5 bytes

ç^0/<C-a>

Where <C-a> is 0x01.

Try it online!

Explanation

ç                   " On every line
 ^0/                " that begins with a zero do:
    <C-a>           " Increment the number on that line

MATL, 3 bytes

t~+

Try it online!

Explanation

t   % Implicit inupt. Duplicate
~   % Logical negation. Converts zero to 1, and nonzero to 0
+   % Add. Implicit display

Mathematica, 9 8 bytes

Per Martin Ender:

#~Max~1&

First idea:

#/. 0->1&

Pure function with replaces 0 with 1. The space is necessary or it thinks we are dividing by .0.

Oasis, 2 bytes

Uses the following formula: a(0) = 1, a(n) = n

n1

Try it online!

TI-BASIC, 7 bytes

:Prompt X
:X+not(X

Alternatively,

TI-BASIC, 7 bytes

:Prompt X
:max(X,1

JavaScript (ES6), 7 bytes

n=>n||1

Jelly, 2 bytes

Try it online!

Pretty much exactly my Pyth answer, but it's my first Jelly program.

C, 27 Bytes

f(n){printf("%d\n",n?n:1);}

Retina, 4 bytes

^0
1

Try it online!

If the input starts with a zero, replace that with a 1. (Works because the input is guaranteed to have no leading zeros for non-zero values.)

Alice, 7 bytes

1/s
o@i

Try it online!

Explanation

1   Push 1. Irrelevant.
/   Reflect to SE. Switch to Ordinal.
i   Read all input as a string.
    Reflect off bottom right corner. Move back NW.
/   Reflect to W. Switch to Cardinal.
1   Push 1.
    IP wraps around to last column.
s   Sort swap: implicitly convert the input to an integer. Then, if the top stack 
    element is less than the one below, the two are swapped. It basically computes
    min and max of two values at the same time, with max on top.
/   Reflect to NW. Switch to Ordinal.
    Immediately reflect off the top boundary. Move SW.
o   Implicitly convert the result to a string and print it.
    Reflect off bottom left corner. Move back NE.
/   Reflect to S. Switch to Cardinal.
@   Terminate the program.

Pyth, 2 bytes

+!

Try it online

Explanation

+!
 !Q    1 if (implicit) input is 0, 0 otherwise.
+  Q   Add the (implicit) input.