index | submit | rank | book

mult1 – Multiplication (easy version)

Three leaves in each of the seven branches of one tree.

Write a program that reads three numbers and prints their product. 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:

$ ./mult1
3 7 1
21

$ ./mult1
234 321 999
75038886

Input and output

Input consists of a single line with three natural numbers x, y and z where 0 ≤ x, y, z ≤ 999.

The output should contain a single line with an integer w where w = x × y × z.

Example input 1

3 7 1

Example output 1

21

Example input 2

234 321 999

Example output 2

75038886

The mult function

For a full score, in addition to producing the correct output, the program should be implemented using a mult function that takes three integers as arguments and returns an integer. Please refer to the information for the chosen language:

The mult function should not print anything. It should just perform the computation and return an integer. The function and input/output processing must exist in the same program. Create a single submission with the function and main program. If you’re confused, try earning a partial score first.

Specifically for this exercise when using Python, JavaScript, Lua or Ruby, avoid using sys.exit(), process.exit(), os.exit() or exit, as your program is appended with some extra assertions in one of the test sets.

Scoring

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

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 three numbers: or Their product is 10. Instead, just print the resulting number followed by a line break as in the example output.

  2. Exit immediately: Your program should print the addition result 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:

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

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

     C:\> mult1.exe
     12 21 2
     504
    
  5. Easier exercises: If you have difficulty with this exercise, try the add1 exercise first.

try first: add1

try next: box1 oddeven1

index | submit | rank | book

Copyright © 2020-2023 Rudy Matela
All rights reserved