##PowerShell v3+ 110 99 107 103 Bytes
PowerShell v3+ 110 99 107 103 Bytes
iwr($x=((iwr "xkcd.com/$args").images|?{$_.title})).src.Trim("/") -outf x.jpg;if($x){ii x.jpg;$x.title} Thanks to Timmy for helping save some bytes by using inline assignments.
If no arguments are passed then $args is null and it will just get the current comic. Download the picture, by matching the one with alt text, into a file in the current running directory of the script. Then display it with the default viewer of jpg's. The alt text is then displayed to console. iwr is an alias for Invoke-WebRequest
If the number passed (or any invalid input for that matter) does not match the process fails with at least a 404 error.
iwr( # Request the comic image from XKCD $x=((iwr "xkcd.com/$args").images| # Primary search to locate either the current image # or one matching an argument passed ?{$_.title})) # Find the image with alt text .src.Trim("/") # Using the images associated link and strip the leading slashes -outf x.jpg # Output the image to the directory local to where the script was run if($x){ # Test if the image acquisition was successful ii x.jpg # Open the picture in with the default jpg viewer $x.title # Display alt text to console } # I'm a closing bracket.