Day 0: Hello World Printing - 30 Days Code - IndianTechnoEra
Latest update Android YouTube

Day 0: Hello World Printing - 30 Days Code

Getting Started with 30 Days of Code on HackerRank

Introduction:

Welcome to the 30 Days of Code challenge on HackerRank! This series is designed to help you hone your coding skills and familiarize yourself with different programming concepts. In this introductory challenge, we'll cover some basic syntax and input/output operations common to many programming languages.

The Challenge:

The task for this challenge is straightforward. You need to read a line of input from stdin, print "Hello, World." on the first line, and then print the contents of the input variable on the second line. This challenge aims to ensure that you are comfortable with basic input/output operations.

Note: The instructions are Java-based, but we support submissions in many popular languages. You can switch languages using the drop-down menu above your editor, and the  variable may be written differently depending on the best-practice conventions of your submission language.

Format & Sample

Input Format

A single line of text denoting  (the variable whose contents must be printed).

Output Format

Print Hello, World. on the first line, and the contents of  on the second line.


Sample Input

Welcome to 30 Days of Code!

Sample Output

Hello, World. 

Welcome to 30 Days of Code!

Explanation

On the first line, we print the string literal Hello, World.. On the second line, we print the contents of the  variable which, for this sample case, happens to be Welcome to 30 Days of Code!. If you do not print the variable's contents to stdout, you will not pass the hidden test case.

Code Breakdown 

Let's break down the code:

Reading Input:

string inputString;

getline(cin, inputString);

We use the getline function to read a line of input from the standard input (stdin) and save it to the inputString variable.


Printing Output:

cout << "Hello, World." << endl;

cout << inputString << endl;

The first cout statement prints the string literal "Hello, World." on the first line. The second cout statement prints the contents of the inputString variable on the second line.

Solution

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
   string inputString; // declare a variable to hold our input
   getline(cin, inputString); // get a line of input from cin and save it to our variable
  
   // Your first line of output goes here
   cout << "Hello, World." << endl;
   
   // Write the second line of output
   cout << inputString << endl;

   return 0;
}



Post a Comment

Feel free to ask your query...
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.