codescracker
c++

C++ Program to Print an Integer



« Previous Program Next Program »

In this article, you will learn and get code to print an integer value using C++ program. Here are the list of programs on printing of an integer (number):

Print an Integer

To print any integer or number on output in C++ programming, just put the variable that holds the value, after cout<< like:

cout<<num;

whatever the value of num is, it gets printed on output. Here is the complete program on printing of an integer value along with some string (or message) before it.

// C++ Program to Print an Integer Value
// ----codescracker.com----

#include<iostream>
using namespace std;
int main()
{
    int num=10;
    cout<<"The Value of 'num' is "<<num;
    cout<<endl;
    return 0;
}

This program was build and run under Code::Blocks IDE. Here is its sample output:

C++ program print integer

You can replace the following statement:

cout<<"The Value of 'num' is "<<num;

with

cout<<num;

To print only 10 on output, without any extra thing.

Print an Integer (Number) entered by User

This program allows user to enter the number. When user enters a number say 10, it gets stored in num. And print the value of num on output in similar way like already discussed in previous program.

// C++ Print an Integer Value entered by User
// ----codescracker.com----

#include<iostream>
using namespace std;
int main()
{
    int num;
    cout<<"Enter the Number: ";
    cin>>num;
    cout<<"\nYou've entered: "<<num;
    cout<<endl;
    return 0;
}

The snapshot given below shows the initial output produced by this program:

print integer entered by user c++

Now supply the input as a number say 10 and then press ENTER to print the entered number back on the output screen as shown in the sample output given below:

c++ print number entered by user

Same Program in Other Languages

C++ Online Test


« Previous Program Next Program »



© Copyright 2021. All Rights Reserved.

CodesCracker