- Prepare
- C++
- Introduction
- Basic Data Types
- Discussions
Basic Data Types
Basic Data Types
+ 0 comments int main() { // Complete the code. int a; long b; char c; float d; double e; scanf("%d %ld %c %f %lf ", &a,&b,&c,&d,&e ); printf("%d\n%ld\n%c\n%.3f\n%.9lf", a,b,c,d,e); return 0; }
+ 0 comments include
include
include
include
include
using namespace std;
int main() { int i; long l; char c; float f; double d; cin>>i>>l>>c>>f>>d; cout< return 0; }
+ 0 comments include
include
using namespace std;
class A { public: A() { int n; long l; char ch; double f; double d; cin >> n >> l >> ch >> f >> d; cout << n << endl; cout << l << endl; cout << ch << endl; cout << fixed << setprecision(15) << f << endl; cout << fixed << setprecision(15) << d << endl; } };
int main() { A obj; return 0; }
+ 0 comments I used scanf and printf and it worked like this
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { // Declare variables int a; long b; char c; float d; double e; // Take input scanf("%d %ld %c %f %lf", &a, &b, &c, &d, &e); // Output it printf("%d\n%ld\n%c\n%.3f\n%.9lf", a, b, c, d, e); return 0; }
+ 0 comments The code you provided is a C++ program that reads input values for different data types (int, long, char, float, and double) from the standard input (usually the keyboard) and then prints them with specified precision using cout. However, there are a few issues with the code:
The #include directive is repeated twice. It's only necessary to include the necessary header files once.
The setprecision function is used without including the required header file .
The code uses using namespace std;, which is generally not recommended in C++ as it can lead to naming conflicts. It's better to specify std:: before the standard library elements explicitly, as shown in the cout lines.
Sort 1441 Discussions, By:
Please Login in order to post a comment