C++ Output Numbers

C++ Tutorial

💻 C++ Output Numbers – Advanced Guide

In C++ Output Numbers are printed using cout.
At an advanced level, this includes formatting, precision control, bases, expressions, loops, and calculations.


1️⃣ Printing Integer Numbers ⭐

Example


 

Output

10

2️⃣ Printing Multiple Numbers in One Statement ⭐


Output

5 10 15

3️⃣ Printing Arithmetic Expressions ⭐


Output

15
50
2

4️⃣ Integer vs Floating-Point Output ⚠️


Output

2
2.5

📌 Integer division removes decimal part.


5️⃣ Printing Floating Numbers with Precision ⭐⭐


 

Output

3.14159
3.14

6️⃣ Printing Numbers Using Loops ⭐

Print numbers from 1 to 5


Output

1 2 3 4 5

7️⃣ Printing Even and Odd Numbers ⭐

Even Numbers


Output

2 4 6 8 10

Odd Numbers


Output

1 3 5 7 9

8️⃣ Printing Numbers in Different Number Systems ⭐⭐⭐


Output

25
31
19

📌

  • oct → octal

  • hex → hexadecimal


9️⃣ Formatting Output Width ⭐⭐


 

Output

50

📌 Right-aligned by default.


🔟 Printing Calculated Results ⭐


Output

Area = 50

1️⃣1️⃣ Scientific Notation Output ⭐⭐⭐


Output

1.234568e+04

1️⃣2️⃣ Common Output Mistakes ❌

❌ Using cout >> instead of cout <<
❌ Forgetting #include <iomanip>
❌ Expecting decimal output from integer division
❌ Missing semicolon ;


📌 Interview Questions (Advanced)

Q1. Why does 5/2 print 2 in C++?
👉 Because both operands are integers.

Q2. How to control decimal precision?
👉 fixed + setprecision()

Q3. Which header is required for output formatting?
👉 <iomanip>


✅ Final Summary

cout prints numbers
✔ Expressions are evaluated before printing
✔ Integer division removes decimals
setprecision() controls decimals
✔ Loops print number sequences
✔ Bases: decimal, octal, hex
✔ Formatting is crucial in exams & interviews

You may also like...