Skip to content
Programming101
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • 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
Programming101
Programmingoneonone

Learn everything about programming

HackerRank Basic Data Types solution in c++ programming

YASH PAL, 31 July 202422 August 2024

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

HackerRank Basic Data Types problem solution in c++ programming.

#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++ Programming Tutorials coding problems solutions Hackerrank Problems Solutions

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes