Table of Contents
In this tutorial, we discuss the simple concept of Program to print an integer in C++ language
problem – How to write a program to print an integer in C++ language?
In this article, we are going to learn How to write a C++ program to print an integer
The following shows two different ways to How to write a C++ program to print an integer and there is an example given to each
The first Example is done by declared and initialized variable
The second Example is done through the user entered the value of the variables
Program 1
//C++ program to print an integer
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int num; //variable declaration
num=56; //variablr initialization
cout << "you declared: " << num<<endl;
getch();
return 0;
}
When the above code is executed it produces the following output
you Declared: 56
Method
Program 2
//C++ program to print an integer
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int num; //variable declaration
cout << "Enter an integer to print: "<<endl;
cin>>num;
cout << "you entered: " << num<<endl;
getch();
return 0;
} When the above code is executed it produces the following output
Enter an integer to print: 100 you entered: 100
Method
Similar post
Write a C program to display an integer
Write a Java program to display an integer
Write a Python program to display an integer
Suggested post
Hello world program in C++ language
Data type in C++ language
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.