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


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

Updated on: 11-Oct-2021

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements