We are providing Basic Data Types Hackerrank Solution in C++ programming language and as well as in C language for better understand the programming challenges in both language. 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. Let's dive into and find out the hackerrank c++ basic data types solution within a minutes.
Some C++ data types, their format specifiers, and their most common bit widths are as follows. But for we will solve or find the solution of hackerrank basic data types solution c++ in priority basis.
Reading
To read a data type, use the following syntax:
For example, to read a character followed by a double:
For the moment, we can ignore the spacing between format specifiers.
Printing(hackerrank basic data types solution c++)
To print a data type, use the following syntax:
For example, to print a character followed by a double:
Pro Hint: You can also use cin and cout instead of scanf and printf; however, if you are taking a million numbers as input and printing a million lines, it is faster to use scanf and printf. So that is the only reason we are providing basic data types hackerrank solution in c++ and C Language.
Input consists of the following space-separated values: int, long, char, float, and double, respectively.
Print each element on a new line in the same order it was received as input. Note that the floating-point value should be correct up to 3 decimal places and the double to 9 decimal places.
Hint: To convert any Bits into Byte divided the Bits by 8, Because of 1 Byte = 8 Bits. This point needs to remember to solve hackerrank basic data types solution c++.
Check: 30 Days of Code Hackerrank Solutions
So as we know we have to use all data types and taking user input and store the user input in all variables after that print the values of all data types.
Now the last step is to print the value hold by Variable and add return statement in the end. Our programming challenge program to basic data types hackerrank solution in c++ done now.
But remember all output should be print in the next line so do not forget to add endl in the end.
Submit your solution here:-Click here
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. Let's dive into and find out the hackerrank c++ basic data types solution within a minutes.
Basic Data Types Hackerrank Solution Logic
Some C++ data types, their format specifiers, and their most common bit widths are as follows. But for we will solve or find the solution of hackerrank basic data types solution c++ in priority basis.
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(hackerrank basic data types solution c++)
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);
Pro Hint: You can also use cin and cout instead of scanf and printf; however, if you are taking a million numbers as input and printing a million lines, it is faster to use scanf and printf. So that is the only reason we are providing basic data types hackerrank solution in c++ and C Language.
Basic Data Types Input/Output Format
Input Format
Input consists of the following space-separated values: int, long, char, float, and double, respectively.
Output Format
Print each element on a new line in the same order it was received as input. Note that the floating-point value should be correct up to 3 decimal places and the double to 9 decimal places.
Sample Input
3 12345678912345 a 334.23 14049.30493
Sample Output
3 12345678912345 a 334.230 14049.304930000
Explanation
Print int 3, followed by long 12345678912345, followed by char a, followed by float 334.23, followed by double 14049.30493.
Hint: To convert any Bits into Byte divided the Bits by 8, Because of 1 Byte = 8 Bits. This point needs to remember to solve hackerrank basic data types solution c++.
Check: 30 Days of Code Hackerrank Solutions
Explanation Basic Data Types in C++ Hackerrank Solution
So as we know we have to use all data types and taking 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 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. Our programming challenge program to basic data types hackerrank solution in c++ done now.
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 end.
Submit your solution here:-Click here
Basic Data Types Hackerrank Solution in C++
#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; }
Hackerrank Basic Data Types 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; }
if we use cout and cin intead of scanf anf printf it is giving error. cam anyone tell me why?
ReplyDeleteHii AARUSHI
DeleteC is closer to the machine circuit, hardware, etc than C++ is. But at the same time C++ "arguably" allows more direct manipulation of your data.you can use iomanip to solve the problem i if you are good in webtechnology Click Here