DEV Community

Cover image for Day 1: Data Types - 30 Days of Code HackerRank
Aayushi Sharma
Aayushi Sharma

Posted on

 

Day 1: Data Types - 30 Days of Code HackerRank

30 days of code

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 your 3 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.

Data Type HackerRank solution in CPP

#include <iostream>
#include <iomanip>
#include <limits>

using namespace std;

int main() {
    int i = 4;
    double d = 4.0;
    string s = "HackerRank ";


    // Declare second integer, double, and String variables.
    int i2;
    double d2;
    string s2;
    // Read and save an integer, double, and String to your variables.
    // Note: If you have trouble reading the entire string, please go back and review the Tutorial closely.
    cin >> i2;
    cin >> d2;
    cin.get();
    getline(cin, s2);
    // Print the sum of both integer variables on a new line.
    cout << i+i2 << endl;
    // Print the sum of the double variables on a new line.    
    cout<< std::fixed <<std::setprecision(1)<< d + d2 << endl;
    // Concatenate and print the String variables on a new line
    cout << s << s2;
    // The 's' variable above should be printed first.

    return 0;

Data Type HackerRank solution in Python

i2 = int(input())
d2 = float(input())
s2 = input()

print(i + i2)
print(d + d2)
print(s + s2)

Data Type HackerRank solution in JavaScript

// Declare second integer, double, and String variables.
// Read and save an integer, double, and String to your variables.
var i2 = +(readLine());
var d2 = +(readLine());
var s2 = readLine();

// Print the sum of both integer variables on a new line.
console.log(i + i2);

// Print the sum of the double variables on a new line.
console.log((d + d2).toFixed(1));

// Concatenate and print the String variables on a new line
// The 's' variable above should be printed first.
console.log(s + s2);

30 days of Code - Hacker Rank Solution aayushi-droid

Top comments (1)

Collapse
 
aaronpaulgz profile image
Aaron Gonzalez

Thanks for this. Had a little doubt you cleared me!

⚡️⛓JavaScript Visualized: Scope

async await

☝️ Check out this all-time classic DEV post