# Hacker Rank solution for Basic Data Types In C++

Problem:- Hacker Rank Solution Program In C++ For " Basic Data Types " or Hacker Rank Solution Program In C++ ForBasic Data Types or Basic Data Types solution hacker rank or Hacker rank solution for c++ domain or Hacker rank solution for basic Data Types sub domain or Basic Data Types solution in c++ of hacker rank or introduction solutions hacker rank.

Check Here:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.

Logic:- for this problem there is no logic we have just simplify all data type and print all value, so for this, we can take an example of all data types and print the output of variable. Before going for a solution first clear the doubts on data type and their size, below is the data type and their size. Some C++ data types, their format specifiers, and their most common bit widths are as follows: or we can use an io-manip Header file to make an easy solution.

Int ("%d"): 32 Bit integer or 4 Byte integer
Long ("%ld"): 64 bit integer 8 Byte integer
Char ("%c"): Character type
Float ("%f"): 32 bit real value 4 Byte integer
Double ("%lf"): 64 bit real value 8 Byte integer

Hint:- For converting any Bits into Byte divided the Bits by 8, the reason is very simple cause 1 Byte = 8 Bits.

Explanation:- So as we know we have to use all data types and taking a user input and store the user input in all variables after that print the values of all data types.

Declare of Data Types

int integer;
long long1;//by default int long
long long long2; //by default int long long
char character;
float floatnumber;
double doublenumber;

Now take a user input and store the value in variables.

cin>>integer;
cin>>long1;
cin>>long2;
cin>>character;
cin>>floatnumber;
cin>>doublenumber;

Now the last step is to print the value hold by Variable and add return statement in the end.

cout << setprecision(20) << integer<< endl;
cout << setprecision(20) << long1<< endl;
cout << setprecision(20) << long2<< endl;
cout << setprecision(20) << character<< endl;
cout << setprecision(20) << floatnumber<< endl;
cout << setprecision(20) << doublenumber<< endl;

return 0;

But remember all output should be print in the next line so do not forget to add endl in the last. A bonus point is for all reader you can also find This problem solution in C language.

Solution:-

#include <iostream>

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

int main()
{

int integer;
long long1;//by default int long
long long long2; //by default int long long
char character;
float floatnumber;
double doublenumber;

cin>>integer;
cin>>long1;
cin>>long2;
cin>>character;
cin>>floatnumber;
cin>>doublenumber;

cout << setprecision(20) << integer<< endl;
cout << setprecision(20) << long1<< endl;
cout << setprecision(20) << long2<< endl;
cout << setprecision(20) << character<< endl;
cout << setprecision(20) << floatnumber<< endl;
cout << setprecision(20) << doublenumber<< endl;

return 0;

}

2. Solution In C:-

#include <iostream>
#include <cstdio>

int main()
{

int a;
long int b;
long long int c;
char d;
float e;
double f;

scanf("%d %ld %lld %c %f %lf",&a,&b,&c,&d,&e,&f);

printf("%d\n%ld\n%lld\n%c\n%f\n%lf",a,b,c,d,e,f);

return 0;

}

Output:-

1. C++ Program Output

2. C Program Output