index | submit | rank | book

repeat1 – Repeat-a-number

Write a program that reads a single number from standard input and repeats it on standard output. The standard input and output are usually the keyboard and screen of a command line session. Here is an example command line session with such a program:

$ ./repeat1
1
1

$ ./repeat1
2
2

If you read 1, write 1; If you read 2, write 2; If you read 3, write 3; etc.

A parrot repeating numbers: 1, 1, 2, 2, 43, 43

Input and Output

Input will contain a single line with a single integer number x. Output should contain a single line with the same number x.

Example input 1

1

Example output 1

1

Example input 2

2

Example output 2

2

Scoring

Submit your solution to be graded according to the following list:

Hints

If you do not know where to start, read the Computer Science by Example book. First, setup your environment then learn the programming basics. Here are some hints:

  1. Automated 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 typed number is 23. Instead, just print the resulting number followed by a line break as in the example output.

  2. Exit immediately: Your program should print the given number then exit immediately. Do not use system("pause"), sleep(1) or anything of sorts.

  3. 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:

     $ ./repeat1 <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”.

    This is actually how the automated judge runs your program.

  4. Windows users: On Windows, you should not use ./ to run a program in the current directory, do instead:

     C:\> repeat1.exe
     23
     23
    
  5. Easier exercises: If you have difficulty with this exercise, try the hello exercise first.

try first: hello

try also: hi1

try next: age1

index | submit | rank | book

Copyright © 2020-2021 Rudy Matela
All rights reserved