[Question]
  [
# Task
Given a non-negative integer `n`, output `1` if `n` is `0`, and output the value of `n` otherwise.
# Input
A non-negative integer.
* If you would like to accept the string as input, the string would match the following regex: `/^(0|[1-9][0-9]*)$/`, i.e. it must not have any leading zeroes, except when it is `0`.
* If you accept a real integer as input, you may assume that the integer is within the handling capability of the language.
# Output
A positive integer, specified above. Leading zeroes are not allowed. Your output should match the regex `/^[1-9][0-9]*$/`.
# Testcases
```
input output
    0      1
    1      1
    2      2
    3      3
    4      4
    5      5
    6      6
    7      7
```
# Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer in bytes wins.
[Standard loopholes](https://codegolf.meta.stackexchange.com/q/1061/48934) apply.
  
[Answer]
# 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!](https://tio.run/nexus/c-gcc#@5@mkadZnWebZ29laF37PzOvRCE3MTNPQ5OrmksBCAqKgEJpGkqqKTF5qilKOgppGgaaINJUU9Oaq/Y/AA)
# C, 17 bytes
```
f(n){return!n+n;}
```
[Try it online!](https://tio.run/nexus/c-gcc#@5@mkadZXZRaUlqUp5innWdd@z8zr0QhNzEzT0OTq5pLAQgKioBCaRpKqikxeaopSjoKaRoGmiDSVFPTmqv2PwA)
# C, 16 bytes
```
#define f(n)!n+n
```
[Try it online!](https://tio.run/nexus/c-gcc#@6@ckpqWmZeqkKaRp6mYp533PzOvRCE3MTNPQ5OrmksBCAqKgEJpGkqqKTF5qilKOkClBpog0lRT05qr9j8A)
[Answer]
## JavaScript (ES6), 7 bytes
```
n=>n||1
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 2 bytes
```
ª1
```
[Try it online!](https://tio.run/nexus/japt#@39oleH//wYA "Japt – TIO Nexus")
### 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`.
[Answer]
## Haskell, 5 bytes
```
max 1
```
Usage example: `(max 1) 0` -> `1`.
Nothing much to explain.
[Answer]
# Pyth, 2 bytes
```
+!
```
[Try it online](http://pyth.herokuapp.com/?code=%2B!&input=42&debug=0)
Explanation
```
+!
 !Q    1 if (implicit) input is 0, 0 otherwise.
+  Q   Add the (implicit) input.
```
[Answer]
## [Alice](https://github.com/m-ender/alice), 7 bytes
```
1/s
o@i
```
[Try it online!](https://tio.run/nexus/alice#@2@oX8yV75D5/78BAA "Alice – TIO Nexus")
### 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.
```
[Answer]
# [V](https://github.com/DJMcMayhem/V), 4 bytes
```
é0À
```
[Try it online!](https://tio.run/nexus/v#@394pcHhBsb///8bAQA "V – TIO Nexus")
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 
* `0` is already a command (go the first column), and
* In the context of a text editor, it rarely makes sense to request that a command be run 0 times.
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
```
[Answer]
# [J](http://jsoftware.com/), 2 bytes
```
^*
```
[Try it online!](https://tio.run/nexus/j#@59maxWn9f9/moKBgqGCkYIxAA "J – TIO Nexus")
`^` [argument] raised to the power of
`*` the sign of the argument (0 if 0 else 1)
Because `1=0^0` in J.
[Answer]
## [Retina](https://github.com/m-ender/retina), 4 bytes
```
^0
1
```
[Try it online!](https://tio.run/nexus/retina#U9VwT/gfZ8Bl@P8/kOAy4jLmMuEy5TLjMuey4LLkMgQKGgIA "Retina – TIO Nexus")
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.)
[Answer]
# 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](https://tio.run/nexus/bash#S8svUihJLS5JTixOVcjMU6g20NMzr7VWSMnnUgCCgqLMvJI0BSXVYgVdOwUlBRWYWrBsanJGPkJIoUYhJVlBN1X9v32KQVGcdsF/da6U/LzU/wA).
[Answer]
# [brainfuck](https://github.com/TryItOnline/tio-transpilers), 8 bytes
```
+>,[>]<.
```
[Try it online!](https://tio.run/nexus/bash#Tc1LCsIwFEbhcbOKn9KZJs1M0JCNiIM@EgjKveEmhaJ17VUcuYDznWmo8CDWzyBsxgjnYPaDP179zZndKBVZQEiEl7XG2NMbF8ysmiyJakTb0RmtatZ1hhboXL6EQ0fY0HOufU2sqwxUcnoEKf0oQ6K4TPf/64Zfn4uamcL@AQ "Bash – TIO Nexus")
[Answer]
# 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!](https://tio.run/nexus/r#@5@bWKFhqFOcnJinoan534DrPwA)
I should note that there is another fine R solution in 13 bytes by [Sven Hohenstein](https://codegolf.stackexchange.com/a/118847/67312) which allows for yet *another* 13 byte solution of
```
(n=scan())+!n
```
which makes me wonder if that's the lower limit for R.
[Answer]
# [Cubix](https://github.com/ETHproductions/cubix), 6 bytes
```
OI!1L@
```
Somehow managed to fit it on a unit cube... [Test it online!](http://ethproductions.github.io/cubix/?code=T0khMUxA&input=MA==&speed=10)
### 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 `@`.
[Answer]
# [Oasis](https://github.com/Adriandmen/Oasis), 2 bytes
Uses the following formula: **a(0) = 1**, **a(n) = n**
```
n1
```
[Try it online!](https://tio.run/nexus/oasis#@59n@P//fxMA "Oasis – TIO Nexus")
[Answer]
# [V](https://github.com/DJMcMayhem/V), 5 bytes
```
ç^0/<C-a>
```
Where `<C-a>` is `0x01`.
[Try it online!](https://tio.run/nexus/v#@394eZyBPuP//wZchlxGXMZcJlymXGZc5lyGBgA "V – TIO Nexus")
### Explanation
```
ç                   " On every line
 ^0/                " that begins with a zero do:
    <C-a>           " Increment the number on that line
```
[Answer]
## **R** 20 16 bytes
```
pryr::f(n+(n<1))
```
[Answer]
# Jelly, 2 bytes
```
+¬
```
[Try it online!](https://tio.run/nexus/jelly#@699aM3///9NjAA "Jelly – TIO Nexus")
Pretty much exactly my Pyth answer, but it's my first Jelly program.
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 3 bytes
```
∅1|
```
[Try it online!](https://tio.run/nexus/brachylog2#@/@oo9Ww5v9/4/9RAA "Brachylog – TIO Nexus")
### 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
```
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 3 bytes
```
1∘⌈
```
[Try it online!](https://tio.run/nexus/apl-dyalog#@@/4qG2C4aOOGY96Ov7/d1Qw4HJUMARiIyA2BmITIDYFYjMgNgcA "APL (Dyalog Unicode) – TIO Nexus")
This takes the ceil of the argument and `1`.
[Answer]
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), ~~22~~, 10 bytes
```
({{}}[]{})
```
[Try it online!](https://tio.run/nexus/brain-flak#@69RXV1bGx1bXav5/78BAA "Brain-Flak – TIO Nexus")
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)
[Answer]
# [Hexagony](https://github.com/m-ender/hexagony), ~~7~~ 6 bytes
```
)?<@.!
```
### Expanded:
```
 ) ?
< @ .
 ! .
```
[Try it online!](https://tio.run/nexus/hexagony#@69pb@Ogp/j/vyEA)
Saved 1 byte thanks to Martin!
If the number is nonzero print it, otherwise add one to it and print that instead.
[Answer]
# [MarioLANG](https://esolangs.org/wiki/MarioLANG), 12 bytes
```
;
=[
:<+
 =:
```
[Try it online!](https://tio.run/nexus/mariolang#@2/NZRvNZWWjzaVga/X/vykA "MarioLANG – TIO Nexus")
**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.
[Answer]
# TI-BASIC, 7 bytes
```
:Prompt X
:X+not(X
```
Alternatively,
# TI-BASIC, 7 bytes
```
:Prompt X
:max(X,1
```
[Answer]
## 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`.
[Answer]
# Python, 15 bytes
```
lambda n:n or 1
```
[Answer]
# 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
```
[Answer]
## Excel, 10 Bytes
```
=A1+(A1=0)
```
This saves 4 Bytes over the obvious 'IF' statement solution, `=IF(A1=0,1,A1)`.
[Answer]
# Perl 5, 6 + 2 bytes for the -l and -p flags
```
$_||=1
```
Takes input on separate lines from stdin. Runs with the flags `-lp`.
[Answer]
## Java 8, 10 bytes
```
i->i<1?1:i
```
* Thanks to [@LeakyNun](https://codegolf.stackexchange.com/users/48934/leaky-nun) for saving -**1** byte
	+ Didn't notice it's a **non-negative** integer
[Answer]
# 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](https://codegolf.stackexchange.com/a/118534/65870)!
]