C++ Program To Print Number Entered By User - Programiz

Tutorials Courses Python JavaScript TypeScript SQL HTML CSS C C++ Java R Ruby RUST Golang Kotlin Swift C# DSA

Become a certified C++ programmer.

ENROLL

Popular Tutorials

C++ if...else Statement C++ for Loop Arrays in C++ Strings in C++ C++ Class & Objects Start Learning C++

Popular Examples

Create a simple calculator Check prime number Print the Fibonacci sequence Check if a number is palindrome or not Program to multiply matrix Explore C++ Examples

Reference Materials

iostream cmath cstring ctime View all Programiz Pro Logo

Created with over a decade of experience.

  • Learn
  • Practice
  • Compete
Learn Python Learn HTML Learn JavaScript Learn SQL Learn DSA Learn C Learn C++ Learn Java View all Courses on Programiz Pro Logo Python Basics Python Intermediate C++ Basics C++ Intermediate C++ OOP C Programming Java Basics Java Intermediate Java OOP View all Courses on Programiz Pro Logo Python Challenges JavaScript Challenges Java Challenges C++ Challenges C Challenges View all Challenges on Programiz Pro Logo Learn Practice Compete

Certification Courses

Created with over a decade of experience and thousands of feedback.

Learn Python Learn HTML Learn JavaScript Learn SQL Learn DSA View all Courses on Programiz Pro Logo Learn C Learn C++ Learn Java Python JavaScript TypeScript SQL HTML CSS C C++ Java More languages

Become a certified C++ programmer.

Try Programiz PRO!

Popular Tutorials

C++ if...else Statement C++ for Loop Arrays in C++ Strings in C++ C++ Class & Objects Start Learning C++ All C++ Tutorials

Reference Materials

iostream cmath cstring ctime View all Python JavaScript C C++ Java R Kotlin

Become a certified C++ programmer.

Try Programiz PRO!

Popular Examples

Create a simple calculator Check prime number Print the Fibonacci sequence Check if a number is palindrome or not Program to multiply matrix All C++ Examples

C++ Examples

  • C++ "Hello, World!" Program
  • Print Number Entered by User
  • Add Two Numbers
  • Find Quotient and Remainder
  • Find Size of int, float, double and char in Your System
  • Swap Two Numbers
  • Find ASCII Value of a Character
  • Multiply two Numbers

C++ Tutorials

  • Calculate Average of Numbers Using Arrays
  • Display Factors of a Number
  • Add Two Matrix Using Multi-dimensional Arrays
  • Find Transpose of a Matrix
  • Access Elements of an Array Using Pointer
  • Calculate Sum of Natural Numbers
C++ Program to Print Number Entered by User

Example: Print 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: 23 You entered 23

This program asks the user to enter a number.

When the user enters an integer, it is stored in variable number using comment.

Then it is displayed on the screen using cout.

Starting from this example, we will be using the std namespace using the code:

using namespace std;

This will allow us to write cout, cin, endl, etc. instead of std::cout, std::cin, std::endl respectively.

This is simply to make our code cleaner and more readable.

However, using the std namespace is considered a bad practice and we highly recommend you drop this practice once you've mastered the basics of C++.

Share on: Did you find this article helpful?

Sorry about that.

How can we improve it? Feedback * Leave this field blank

Your builder path starts here. Builders don't just know how to code, they create solutions that matter.

Escape tutorial hell and ship real projects.

Try Programiz PRO
  • Real-World Projects
  • On-Demand Learning
  • AI Mentor
  • Builder Community

Related Examples

C++ Example

Display Factors of a Number

C++ Example

Calculate Average of Numbers Using Arrays

C++ Example

Add Two Matrix Using Multi-dimensional Arrays

C++ Example

Check Whether a Number is Palindrome or Not

Tag » How To Print In C++