Skip to content
Programmingoneonone
Programmingoneonone
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

HackerRank Basic Data Types solution in C++ programming

YASH PAL, 31 July 202416 January 2026

HackerRank C++ Basic Data Types solution – In this HackerRank Basic Data Types problem solution in the C++ programming language, some C++ data types, their format specifiers, and their most common bit widths are as follows:

Int (“%d”): 32 Bit integer

Long (“%ld”): 64 bit integer

Char (“%c”): Character type

Float (“%f”): 32 bit real value

Double (“%lf”): 64 bit real value

Reading

To read a data type, use the following syntax:

scanf(“`format_specifier`”, &val)

For example, to read a character followed by a double:

char ch;

double d;

scanf(“%c %lf”, &ch, &d);

For the moment, we can ignore the spacing between format specifiers.

Printing

To print a data type, use the following syntax:

printf(“`format_specifier`”, val)

For example, to print a character followed by a double:

char ch = ‘d’;

double d = 234.432;

printf(“%c %lf”, ch, d);

HackerRank Basic Data Types solution in c++ programming

C++ Basic Data Types problem solution.

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a; long b; char c; float d; double e;
    cin>>a>>b>>c>>d>>e;
    cout<<a<<"n"<<b<<"n"<<c<<"n";
    cout<<fixed<<setprecision(3)<<d<<"n";
    cout<<fixed<<setprecision(9)<<e<<"n";
    return 0;
}

Second solution

#include <iostream>
#include <cstdio>
#include <iomanip> 
using namespace std;

int main() {
    
    int a;
    long b;
    char c;
    float d;
    double e;
    cin >> a >> b >> c >> d >> e;
    cout<< a << 'n' << b << 'n' << c << 'n';
    cout << std::fixed << std::setprecision(3) << d << 'n';
    cout << std::fixed << std::setprecision(9) << e << 'n';
    
    return 0;
}

Third solution

#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    // Complete the code.
    int i;
    long l;
    char c;
    float f;
    double d;
    scanf("%d %ld %c %f %lf" , &i, &l, &c, &f, &d);
    printf("%dn%ldn%cn%.3fn%.9lfn", i,l,c,f,d);

    return 0;
}
C++ Solutions coding problems solutions Hackerrank Problems Solutions cppHackerRank

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

HackerRank C++ Problems Solutions
Say “Hello, World!” with C++ solution
Input and Output solution
Basic Data Types solution
Conditional Statements solution
For loop solution
Functions solution
Pointer solution
Arrays Introduction solution
Variable-Sized Arrays solution
Attribute Parser solution
StringStream solution
Strings solution
Structs solution
Class solution
classes and objects solution
Box It! solution
Inherited code solution
Exceptional server solution
Virtual Functions solution
Abstract Classes — Polymorphism solution
Vector-Sort solution
Vector-Erase solution
Lower Bound-STL solution
Sets-STL solution
Maps-STL solution
Print Pretty solution
Deque-STL solution
Inheritance Introduction solution
Hotel Prices solution
Cpp exception handling solution
Rectangle Area solution
Multi-Level Inheritance solution
Overloading Ostream Operator solution
Messages Order solution
Accessing Inherited Functions solution
Magic Spells solution
C++ Class Templates problem solution
Preprocessor Solution
Operator Overloading solution
Overload Operators solution
Attending workshops solution
C++ Class Template Specialization solution
C++ Variadics problem solution
Bit Array solution

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes