2 min to read
HackerRank 30 Days of Code Solution Day 1: Data Types
We are going to solve HackerRank’s “30 Days of Code” programming problem on day 1 Data Types
HackerRank solution in C++, Python and JavaScript language with complete code.
Disclaimer: We encourage you to solve this challenge yourself before reading our tutorial. We have provided a detailed explanation of the problem and our solutions to help you check your work.
Hackerrank 30 days of code
It’s part of hackerrank’s 30 days of code. A series of 30-day programming challenges. Where you can learn new programming languages by solving the coding challenges.
Task (30 Days of Code - HackerRank)
Complete the code in the editor below. The variables i
,d
,s
and are already declared and initialized for you. You must:
- Declare
3
variables: one of type int, one of type double, and one of type String. - Read
3
lines of input from stdin (according to the sequence given in the Input Format section below) and initialize your3
variables. - Use the
+
operator to perform the following operations:- Print the sum of
i
plus your int variable on a new line. - Print the sum of
d
plus your double variable to a scale of one decimal place on a new line. - Concatenate
s
with the string you read as input and print the result on a new line.
- Print the sum of
Data Type HackerRank solution in C++
Data Type HackerRank solution in Python
Data Type HackerRank solution in JavaScript
Explanation
- First we declared the three variables
i2
,d2
,s2
of different data types.i2
is an integer,d2
is a double, ands2
is a string. - Then we read the input from the user. We read the integer, double, and string from the user.
- Then we add the integer and double and print the result and round the result to the 1 decimal place.
- Then we concatenate the string and print the result.
In the test case i = 4
, d = 4.0
, s = HackerRank
and the user input is 12
, 4.0
, is the best place to learn and practice coding!
then the output will be like this in the test case.