C++ Program to Print Number Entered by User
In this example, we will learn to print the number entered by a user using C++ cout statement.
Example: Program to Display Number Entered by User
#include <iostream>
using namespace std;
int main()
{
int number;
cout << "Enter an integer: ";
cin >> number;
cout << "You entered: " << number;
return 0;
}
Output
Enter an integer: 20 You entered: 20
Working of above Program
This program asks user to enter a number.
When user enters an integer, it is stored in variable number using cin
. Then it is displayed in the screen using cout
.
Next Example
We hope that this Example helped you develop better understanding of the concept of Program to Print Number Entered by User in C++.
Keep Learning : )
In the next Example, we will learn about C++ Program to Add Two Numbers
.