-
Notifications
You must be signed in to change notification settings - Fork 1
/
BasicDataTypesHR.cpp
75 lines (60 loc) · 1.78 KB
/
BasicDataTypesHR.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
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);
Note: 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.
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 ,
followed by long ,
followed by char ,
followed by float ,
followed by double .
*/
// SOLUTION
#include <iostream>
#include <cstdio>
#include<bits/stdc++.h>
using namespace std;
int main() {
// Complete the code.
int n1;
long n2;
char c1;
float n3;
double n4;
cin>>n1>>n2>>c1>>n3>>n4;
cout<<n1<<"\n"<<n2<<"\n"<<c1<<"\n";
cout<<fixed<<setprecision(3)<<n3<<"\n";
cout<<fixed<<setprecision(9)<<n4;
return 0;
}