Printing array using Do While Loop in C++
This is a simple C++ program that prints the elements of an integer array using a do-while loop. Here's a brief explanation of what the program does:
- Declare an integer array arr with 4 elements and initialize it with values 23, 86, 13, and 15.
- Declare an integer variable i and initialize it with 0.
- Enter a do-while loop. This loop will execute at least once, regardless of whether the condition is true or false.
- Inside the loop, print the value of the i-th element of the arr array using the cout statement. Then increment i by 1.
- Check the condition i<4. If it is true, go back to step 4 and repeat the loop. If it is false, exit the loop.
- End the program by returning 0.
Source Code
#include<iostream>
using namespace std;
int main()
{
int arr[]={23,86,13,15};
int i=0;
do
{
cout<<arr[i]<<endl;
i++;
}
while(i<4);
return 0;
}
To download raw file
Click Here
Output
2386
13
15