On the HackerRank Coding environment, most of your programs require to read input and write the output using the Standard Input stream (STDIN) and the Standard Output stream (STDOUT) methods. You must use the language-specific input and output statements in your code. For example, if you are coding in C, you must use the scanf() statement to read input into your program and printf() to write the output.
In your Hacker Tests, you can access a ready-reckoner to know the programming language specific STDIN and STDOUT methods to use for reading input and writing the output from your code. You can also see the HackerRank Environments Page for information.
- In the Test, click the icon on the left, and select F.A.Q. Scroll down in the page to refer the input-output methods to be used for coding in different programming languages.
- Alternatively, in the code editor, access the section shown below for help, and select the Click here link.
This is the standard stream to provide or read input values to a program. For example, consider a HackerRank sample question to read two integers, say a and b, and return their sum as the output.
- If coding in C#, you must use Console. ReadLine() to read input values from Test Cases into the variables a and b.
b = Console.Readline();
- If coding in C, you must use the scanf() statement to read the integer value inputs to your program.
scanf("%d,%d", &num1, &num2)
This is the standard stream to write or print the output from your code. For example, for the above-mentioned coding question, you need to write the output from your program.
- If coding in C#, you must use the Console.WriteLine() statement to print the output value.
- If coding in C, you must use the printf() statement to write the output value from your program.
You can access the HackerRank Sample Test to practice coding and familiarize yourself with the environment before taking up the actual Test.
In your HackerRank coding tests, to execute your code successfully and return the expected output, it is essential that you provide the expected input(s) to your program and print the output value(s) in the exact expected format. For detailed information, refer to the following topics: