# C++ Programming Code Examples

## C++ > For Loops and While Loops Code Examples

### Displaying array elements using do-while loop

C++ Swap 2 Numbers using Built in Swap -
C++ code which take two numbers from user and swap using built in swap function. Code takes two input and displays numbers before and after swapping. Note: If we remove std::

Program to Find number of Days in month -
Program code enter Month number between 1-12 and print number of days in month using If Else. Input month number from user. Store it in a variable say month and for each month

Using the Bellman-Ford Algorithm to Find -
Using the bellman-ford algorithm to find the shortest path between two vertices assuming that negative size edges exist in the graph. A Program to find the 'shortest path' algorithm

Demonstrates Printf Inside Another Printf -
Firstly Inner printf is executed which results in printing 1324. Printf returns 'Total Number' of Digits:4 & second inner printf will looks like. It prints 4 & Returns the Total Number of digits

Code Finds the Median of 2 Sorted Arrays -
Algorithm finds the median of 2 sorted arrays using binary search approach. Takes the input of 'n' Data Elements of both the arrays. Using decrease, conquer method find the combined

C++ Program to Find LCM of two Integers -
Examples on different ways to calculate LCM ("Lowest Common Multiple") of two integers using loops and decision making statements. "LCM of two integers" a and b is the smallest

Reads Input until Enters a Positive Integer -
C Language program to read input until user enters a positive integer. Positive Numbers 1, 2, 3... are known as natural numbers. C code below takes a positive integer (let say n) as...

Whether a Path Exists Between two Given -
We create a queue for BFS. Mark the current node as visited and enqueue it. It will be used to get all adjacent vertices of a vertex. Get all adjacent vertices of the dequeued vertex s. If