Write a program that reads a single number and prints its increment, i.e. its value added to one.
Your program should read from the standard input and print to the standard output. The standard input and output devices are usually the keyboard and screen of a command line session. Here are a few example sessions:
$ ./inc1
2
3
$ ./inc1
123
124
The input contains a single line with one integer x where
0 ≤ x ≤ 100 000.
The output should contain a line with a single integer y where y = x + 1 and should be terminated by a line break.
2
3
123
124
inc
functionFor a full score,
in addition to producing the correct output,
the program should be implemented using a inc
function
that receives one integers as argument and returns an integer.
Please refer to the information for the chosen language:
int inc(int x);
inc :: Int -> Int
def inc(x):
int inc(int x);
public static int Inc(int x)
inside a class Program
public static int inc(int x)
inside a public class Inc
function inc(x)
function inc(x)
def inc(x)
If you’re confused, try earning a partial score first.
Submit your solution to be graded according to the following list:
inc
functionAutomated judge: Keep in mind that when your program is submitted it will not be run by a human but instead by an automated judge. Instructions should be followed exactly or the judge will not give you a full score.
Your program should not print messages like
Please type a number:
or The increment is 10.
Instead, just print the resulting number
followed by a line break
as in the example output.
Exit immediately:
Your program should print the addition result then exit immediately.
Do not use system("pause")
, sleep(1)
or anything of sorts.
Redirecting input: On most systems (Windows / Linux / OS X), it is possible to redirect the standard input and output of your program to files, like so:
$ ./inc1 <inputfile.txt >outputfile.txt
If you create a plain text file with the “example input”, the above command should produce a plain text file with the “example output”.
Windows users:
On Windows, you should not use ./
to run a program in the current directory,
do instead:
C:\> inc1.exe
41
42
Easier exercises: If you have difficulty with this exercise, try the hello and repeat1 exercises first.
try first: repeat1
try also: triple1
try next: add1
Copyright © 2020-2021 Rudy Matela
All rights reserved