C++ program to print values of different data types provided as input

C++Server Side ProgrammingProgramming

Suppose we are given an integer value, a long value, a character value, a float value, and a double value as inputs. We have to print the values that are given to us as input maintaining their precision.

So, if the input is like integer value = 15, long value = 59523256297252, character value = 'y', float value = 367.124, double value = 6464292.312621, then the output will be

15
59523256297252
y
367.124
6464292.31262

To solve this, we will follow these steps −

  • Print the values given as input in separate lines.

Example

Let us see the following implementation to get better understanding −

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

void solve(int a, long b, char c, float d, double e) {

   cout << a << endl << b << endl << c << endl << d << endl;
   printf("%.5f", e);
}
int main() {
   solve(15, 59523256297252, 'y', 367.124, 6464292.312621);
   return 0;
}

Input

15, 59523256297252, 'y', 367.124, 6464292.312621

Output

15
59523256297252
y
367.124
6464292.31262
raja
Published on 11-Oct-2021 12:01:08
Advertisements