Overview
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 read input and write the output from your code. You can also see the HackerRank Environments Page for information.
- You can check here for the input-output methods for coding in different programming languages.
STDIN
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.
a= Console.Readline();
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)
STDOUT
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.
Console.WriteLine(sum);
- If coding in C, you must use the printf() statement to write the output value from your program.
printf("%dln", a+b);
You can access the HackerRank Sample test to practice coding and familiarize yourself with the environment before taking up the actual test. You can access the Sample test from the test login page.
In your HackerRank coding tests, to execute your code successfully and return the expected output, you must 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: