[Question]
  [
Your task is to take in one integer input and print a zigzag pattern using slashes and backslashes.
* The integer input determines the length of each zig and zag, as well as the number of zigs and zags
* The pattern always starts from right to left
# Test Cases
```
4->
   /
  /
 /
/
\
 \
  \
   \
   /
  /
 /
/
\
 \
  \
   \
2->
 /
/
\
 \
0->
1->
/
8->
       /
      /
     /
    /
   /
  /
 /
/
\
 \
  \
   \
    \
     \
      \
       \
       /
      /
     /
    /
   /
  /
 /
/
\
 \
  \
   \
    \
     \
      \
       \
       /
      /
     /
    /
   /
  /
 /
/
\
 \
  \
   \
    \
     \
      \
       \
       /
      /
     /
    /
   /
  /
 /
/
\
 \
  \
   \
    \
     \
      \
       \
```
  
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~108~~ ~~102~~ ~~101~~ ~~98~~ ~~80~~ ~~76~~ 72 bytes
* Saved six bytes thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen); removing parentheses and golfing `N-n-1` to `N+~n`
* Saved a byte by moving `Z`'s incrementation into the loop condition
* Saved three bytes by using `printf("%c\n",...)` instead of `putchar(...)` and `,puts("")`
* Saved eighteen (!) bytes thanks to [HatsuPointerKun](https://codegolf.stackexchange.com/users/72535/hatsupointerkun); using `printf("%*s",n,"");` to print `n` spaces instead of using a loop `j;for(j=n;j--;)putchar(32);` and combining both `printf(...);` calls
* Saved four bytes by using `printf("%*c",-~n,...);` instead of `printf("%*s%c",n,"",...);`
* Saved four bytes thanks to [nwellnhof](https://codegolf.stackexchange.com/users/9296/nwellnhof); moving everything inside one loop instead of two
```
j;f(k){for(j=0;j<k*k;j++)printf("%*c\n",j/k%2?j%k+1:k-j%k,j/k%2?92:47);}
```
[Try it online!](https://tio.run/##S9ZNT07@/z/LOk0jW7M6Lb9II8vWwDrLJlsr2zpLW1uzoCgzryRNQ0lVKzkmT0knSz9b1cg@SzVb29AqWxdIQ0UsjaxMzDWta/97WecmZuZpQIzysq0zsPbS1rYxNLDWTNPw0tQpKC0p1lBSAqkEAA "C (gcc) – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~16~~ ~~10~~ 9 bytes
```
ＦＮ«↖Ｉθ→‖Ｔ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z8tv0hBwzOvoLTErzQ3KbVIQ1NToZqLM6AoM69Ewyq0wCc1rURHwTmxuESjUFPTmovTN78sVcMqKDM9owTEDUpNy0lNLgkpSswrBpqVqwEUrP3/3@S/btl/3eIcAA "Charcoal – Try It Online") Link is to verbose version of code.
[Answer]
# [MATL](https://github.com/lmendo/MATL), 17 bytes
```
:"GXy@o?P47}92]*c
```
[**Try it online!**](https://tio.run/##y00syfn/30rJPaLSId8@wMS81tIoViv5/38TAA "MATL – Try It Online")
### Explanation
```
:         % Implicit input, n. Push range [1 2 ... n]
"         % For each k in that range
  G       %   Push n again
  Xy      %   Identity matrix of that size
  @       %   Push k
  o?      %   If it's odd
    P     %     Flip the matrix upside down
    47    %     Push 47 (ASCII for '/')
  }       %   Else
    92    %     Push 92 (ASCII for '\')
  ]       %   End
  *       %   Multiply each entry of the matrix by that number
  c       %   Convert to char. Char 0 is shown as space
          % Implicit end. Implicit display
```
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), ~~117~~ ~~103~~ 101 bytes
```
a=>{for(int z=a+1,e=0;e<a*a;)System.Console.WriteLine(e++/a%2<1?"/".PadLeft(--z):@"\".PadLeft(z++));}
```
[Try it online!](https://tio.run/##RY7BCsIwEETv/YpQEBJjWxVPtqmK1woFD168rOkWAjWRJgq29Ntj0YJzmeHNLoy0kTQt@sfz1ihJZAPWkjLog4CMmqh14EZ7GVWREyhN2bedjsj5bR3e44N0yuhMaZeTmggPIu9r09IRkE4AXy1QLFPMYA4pm36ORlvTYHxplcNCaaTIeQKzdbbahUkYl1AVWDsaRR3b7sPrn3ScM5YOPv1tqOmGTXEIBv8B "C# (.NET Core) – Try It Online")
[Answer]
# [SOGL V0.12](https://github.com/dzaima/SOGL), ~~13~~ ~~12~~ 9 [bytes](https://github.com/dzaima/SOGL/blob/master/chartable.md)
```
╝F{±↔}P}ø
```
[Try it Here!](https://dzaima.github.io/SOGLOnline/?code=JXUyNTVERiU3QiVCMSV1MjE5NCU3RFAlN0QlRjg_,inputs=NA__)
could be 8 bytes `╝F{±↔}P}` if the 0 test-case wasn't required
Explanation:
```
       }   implicitly started loop repeated input times
╝            create a down-right diagonal of the input
 F           get the current looping index, 1-indexed
  {  }       that many times
   ±↔          reverse the diagonal horizontally
      P      print that
        ø  push an empty string - something to implicitly print if the loop wasn't executed
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~69~~ ~~68~~ 62 bytes
-1 byte thanks to Jonathan Frech
```
lambda n:[[~i,i][i/n%2]%n*' '+'/\\'[i/n%2]for i in range(n*n)]
```
[Try it online!](https://tio.run/##LcixDkAwFAXQX3mLvBYhEZPEl7QdKpQn3Epjsfj1WpzxXM@9RXQ5jDYf/pxmTxiMeaUWZ6RF0bkCJRNX3FrLf4WYSEhAyWNdFEpol68kuIktuNmjQAXVa50/ "Python 2 – Try It Online")
[Answer]
# Mathematica, 84 ~~90~~ bytes
```
(n=#;Grid@Array[If[Abs[n-(s=Mod[#-1,2n])-.5]==#2-.5,If[s<n,"‌​/","\\"],""]&,{n^2,n‌​}])&
```
* *Thank Jenny\_mathy for -6 bytes.*
I have no idea why `\` is obviously darker than `/`.
[![enter image description here](https://i.stack.imgur.com/X2o2nl.png)](https://i.stack.imgur.com/X2o2nl.png)
[Answer]
# [Jq 1.5](https://stedolan.github.io/jq/), ~~94~~ 89 bytes
```
["/","\\"][range($n)%2]as$s|range($n)|[(range(if$s=="/"then$n-.-1 else. end)|" "),$s]|add
```
Explanation
```
  ["/","\\"][range($n)%2] as $s                         # for $s= / \ / \ $n times 
| range($n)                                             # for .=0 to $n-1
| [(range(if $s=="/" then $n-.-1 else . end)|" "), $s]  # form list of spaces ending with $s
| add                                                   # concatenate
```
Sample Run
```
$ jq -Mnr --argjson n 5 '["/","\\"][range($n)%2]as$s|range($n)|[(range(if$s=="/"then$n-.-1 else. end)|" "),$s]|add'
    /
   /
  /
 /
/
\
 \
  \
   \
    \
    /
   /
  /
 /
/
\
 \
  \
   \
    \
    /
   /
  /
 /
/
```
[Try it online!](https://tio.run/##PYtBCsMgEAC/IssWImRTWnrNS4wHQdtaZE2zhlx8e61Q6G1mYF7vdlNOFHJtBs4wwrKANZvjRxiQ9elqnaDUf6hm@HG8o8xzX8ozMDJNdFEhSZhUYK8rKNAjiq3O@9Y@eS0xszQi3lOiyOteumzuoLyXLl8 "jq – Try It Online")
[Answer]
# Java 8, ~~140~~ ~~134~~ 116 bytes
```
n->{String r="";for(int a=0,b,c;a++<n;)for(b=n;b-->0;r+=a%2>0?"/\n":"\\\n")for(c=b-n+b|-a%2;++c<b;r+=" ");return r;}
```
-24 bytes thanks to *@Nevay*.
**Explanation:**
[Try it here.](https://tio.run/##hZDBasMwEETv/YpFULBQ5Lqhh1JF7hc0lx7rHlaKUpQ6ayPLgZL6213Z8bUYJMTOm4UZnfCCsmkdnQ7fo62x6@ANPV3vADxFF45oHeynEeA9Bk9fYLNEgLhK4pBuOl3E6C3sgUDDSLK8Lt6gGVPHJswrqIuN2ViFQuxI8Uk2mpSRsixUEBrvt2Xxyh4qYi@sqtIze6w2koT5lYkrIezOTGYGjKvgYh8IghpGdUvS9qZOSZZAl8Yf4Jz6ZLc8H5@AfCnz00V3zps@5m1CsaaMcpsVfO71L39c4dsV/rTCn/nyr8P4Bw)
```
n->{                // Method with integer parameter and String return-type
  String r="";      //  Result-String
  for(int a=0,b,c;  //  Index integers
      a++<n;)       //  Loop (1) from 0 to the input (exclusive)
    for(b=n;        //   Reset `b` to the input
        b-->0;      //   Inner loop (2) from the input to 0 (exclusive)
                    //     After every iteration: 
        r+=a%2>0?"/\n":"\\\n") 
                    //      Append either of the slashes + a new-line
      for(c=b-n+b|-a%2;++c<b;r+=" ");
                    //    Append the correct amount of spaces
                    //   End of inner loop (2) (implicit / single-line body)
                    //  End of loop (1) (implicit / single-line body)
  return r;         //  Return the result-String
}                   // End of method
```
[Answer]
# Javascript ES8, 83 79 78 76 75 74 71 bytes
\*reduced 1 byte with ES8 thanks to Shaggy
```
A=(m,i=0)=>i<m*m?`/\\`[x=i/m&1].padStart(x?i%m+1:m-i%m)+`
`+A(m,++i):""
```
[Test here](https://tio.run/##y0osSyxOLsosKNHNy09J/f/f0VYjVyfT1kDT1i7TJlcr115JQUmvKLUgNbFEI1M/V83QPlM11ypXF0jqGmpqK@nHxChFZ2prg6RitZVi8pS0HUEmaFopKf1Pzs8rzs9J1cvJT9dw1DDU1LTmQhUywhQyxhQyAQr9BwA)
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 20 bytes
```
Lm+*;dbQjs<*,_y\/y\\
```
[Try it online!](http://pyth.herokuapp.com/?code=Lm%2B%2a%3BdbQjs%3C%2a%2C_y%5C%2Fy%5C%5C&input=3&debug=0)
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 81 bytes
```
param($a)if($a){1..$a|%{((1..$a|%{" "*--$_+'\'}),($a..1|%{" "*--$_+'/'}))[$_%2]}}
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/vyCxKDFXQyVRMzMNRFYb6umpJNaoVmtowFhKCkpauroq8drqMeq1mjpAVXp6hiji@kBxzWiVeFWj2Nra////GwMA "PowerShell – Try It Online")
Ugh, this is ugly. So much repeated code, plus 7 bytes required to account for `0` special case. *Golfing suggestions welcome.*
[Answer]
# Pyth, 17 bytes
```
js<*_+RV"\/"_B*L;
```
Try it online: [Demonstration](http://pyth.herokuapp.com/?code=js%3C%2A_%2BRV%22%5C%2F%22_B%2AL%3B&input=3&debug=0)
### Explanation:
```
js<*_+RV"\/"_B*L;QQQ   implicit Qs at the end
              *L;Q     list with ["", " ", "  ", ..., " "*(input-1)]
            _B         bifurcate with reverse: [["" to "   "], ["   " to ""]]
     +RV"\/"           append to each one either "\" or "/": 
                       [["\", to "   \"], ["   /" to "/"]]
    _                  reverse
   *              Q    repeat input times
  <                Q   but only take the first input many
 s                     flatten the list of lists
j                      print on each line
```
[Answer]
# Python 3: ~~90 Bytes~~ 82 Bytes
```
lambda n:"\n".join(" "*(abs(i%(n*2)-n+i//n%2)-1)+"/\\"[i//n%2]for i in range(n*n))
```
Thanks to @Jonathan Frech for pointing out that print wasn't needed and that the first zig was the wrong way
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~17~~ 16 bytes
```
F<„/\Nèú.sNƒR}»,
```
[Try it online!](https://tio.run/##MzBNTDJM/f/fzeZRwzz9GL/DKw7v0iv2OzYpqPbQbp3//00A "05AB1E – Try It Online")
**Explanation**
```
F                  # for N in [0 ... input-1] do
  „/\              # push the string "/\"
     Nè            # cyclically index into this string with N
 <     ú           # prepend input-1 spaces to this string
        .s         # get suffixes
          NƒR}     # reverse the list of suffixes input+1 times
              »,   # join on newline and print
```
**Current best attempt using canvas:**
```
F„/\Nè©53NèΛ2®ð«4Λ
```
[Answer]
## C++, ~~92~~ 91 bytes
-1 bytes thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen)
```
void m(int n){for(int i=0,j;i<n;++i)for(j=0;j<n;++j)printf("%*c\n",i%2?j+1:n-j,i%2?92:47);}
```
Thanks to the power of the magic `printf`
[Answer]
# [Java (OpenJDK 8)](http://openjdk.java.net/), ~~131~~ ~~106~~ ~~98~~ ~~96~~ ~~94~~ 91 bytes
```
i->{for(int j=0;j<i*i;System.out.printf("%"+(j/i%2<1?i-j%i:j%i+1)+"c\n",47+45*(j++/i%2)));}
```
[Try it online!](https://tio.run/##TY7BSsQwFEX3/YpQKCSNjY5UBNMZEVeuZ6kuYiYtL7ZJSV4GZOi311Rm4YW3OfdxOVadVeNn4@zpe4Vp9gGJzUwgTEbUsvjPEsIo@uQ0gndbWehRxUheyKUgOREVgibk1buYJhO6N4dmMOFAEtmv0BwuvQ8UXJ7b30nbQQ3y@BPRTMInFHPIVU/LquTU3kJ13@2eobEVPOXjO8ZL/eHKm/aRtw81tZxvP4wxuaxZZROY09eYBa4eZw8nMilw9Ih5enj/JCoMkV1ttyShtDYz0pbJP7gUy/oL "Java (OpenJDK 8) – Try It Online")
[Answer]
# [Dyalog APL](https://www.dyalog.com/), ~~39~~ ~~36~~ ~~35~~ 34 bytes
```
{↑((,⍵ ⍵⍴(⌽,⊢)⍳⍵)/¨' '),¨⍵/⍵⍴'/\'}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT////1HfVE//R20TDLjSgGT1o7aJGho6j3q3KgDxo94tGo969uo86lqk@ah3M1BEU//QCnUFdU2dQyuAPH2IGnX9GPVaLqBBQAPSFEz//wcA "APL (Dyalog Unicode) – Try It Online")
1 byte saved thanks to [Zacharý](https://codegolf.stackexchange.com/users/55550/zachar%c3%bd)
[Answer]
# [Perl 5](https://www.perl.org/), 70 + 1 (`-n`) = 71 bytes
```
$n=$_**2;$_=$"x--$_.'/';say&&s% /%/ %||s%\\ % \\%||y%\\/%/\\%while$n--
```
[Try it online!](https://tio.run/##DchBCoAgEADAr0jsGgSrFnUKn9APBOkgJIRFBhX09jZvw@zhWAdmSBZ803QjeAvVTQRe1boe8/xImVFo1ALfN6NzAoVzxU9x6eJriWuARMTcf9t@xi1lpmlQpjVM6Qc "Perl 5 – Try It Online")
[Answer]
# [Kotlin](https://kotlinlang.org), 102 bytes
```
(0..q-1).map{r->if(r%2<1)q-1 downTo 0 else{0..q-1}.map{(1..it).map{print(' ')};println('/'+45*(r%2))}}
```
[Try it online!](https://tio.run/##NY3BDoIwEETvfMWGxLCraQXFCyKJR8/6A00E0ggFSo0R0m9HLDqnyezbmUdjKqmm4qlgwC65KENwgglDzjsWEa9FO2qWyQL1apdGNIdwb17q1kAIedXn40JaR2LEuTTLV6ulMhhAQPbofKUw2Aab@LD@dhFZ62ZrIRUKXfYJnLUW7/RqZrrMCEYPZg0YkzP/Ep8x5tPvtifPTh8 "Kotlin – Try It Online")
[Answer]
# Excel VBA, ~~84~~ 83 Bytes
Anonymous VBE immediate window function that takes input from range `[A1]` and outputs to the VBE immediate window
```
For i=1To[A1]:For j=1To[A1]:?IIf(i mod 2,Space([A1]-j)&"/",Space(j-1)&"\"):Next j,i
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 15 bytes
```
ḶṚ⁶ẋm0ż⁾/\x$ṁ²Y
```
[Try it online!](https://tio.run/##ASgA1/9qZWxsef//4bi24bma4oG24bqLbTDFvOKBvi9ceCThuYHCsln///84 "Jelly – Try It Online")
Full program.
[Answer]
# [Haskell](https://www.haskell.org/), ~~86~~ 85 bytes
```
f n=take(n*n)$cycle$[(' '<$[x..n-1])++"/"|x<-[1..n]]++[(' '<$[2..x])++"\\"|x<-[1..n]]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P00hz7YkMTtVI08rT1MluTI5J1UlWkNdQd1GJbpCTy9P1zBWU1tbSV@ppsJGN9oQKBIbq60NU2Gkp1cBlo@JQVbwPzcxM0/BViElX4FLAQhyEwt8FQpKS4JLinzyFFQU0hRM/wMA "Haskell – Try It Online")
*Saved one byte thanks to Laikoni*
Repeat a zig ++ a zag, and take the first `n*n` lines.
[Answer]
# [J](http://jsoftware.com/), ~~39 35 33 32~~ 25 bytes
```
' /\'{~[,/@$(|.,:+:)@=@i.
```
[Try it online!](https://tio.run/##y/r/P9FWT0FdQT9GvbouWkffQUWjRk/HSttK08HWIVPvf2pyRr5CooIJF5RhCGMY/wcA "J – Try It Online")
[Answer]
# Dyalog APL, ~~41~~ 40 bytes
`⎕IO` must be `0`.
```
{⍪/((⌽⍵ ⍵⍴S↑'/')(⍵ ⍵⍴'\'↑⍨S←⍵+1))[2|⍳⍵]}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT////1HfVE//R20TDLiALCBd/ah3lb6GxqOevY96tyoA8aPeLcGP2iaq66traiCE1GPUgYKPelcA5SYAhbQNNTWjjWoe9W4GcmJrTf//BwA)
[Answer]
# [D](https://dlang.org/), 105 bytes
```
import std.stdio;void m(T)(T n){for(T i,j;i<n;++i)for(j=0;j<n;++j)printf("%*c\n",i%2?j+1:n-j,i%2?92:47);}
```
[Try it online!](https://tio.run/##S/n/PzO3IL@oRKG4JEUPiDPzrcvyM1MUcjVCNDVCFPI0q9Pyi4CMTJ0s60ybPGtt7UxNkEiWrYF1FpifpVlQlJlXkqahpKqVHJOnpJOpamSfpW1olaebBWZbGlmZmGta1/6HGJyYmaehWc3FmathomnNVfsfAA "D – Try It Online")
Lifted from HatsuPointerKun's C++ answer.
]