In this tutorial, we will discuss the concept of C++ example to print elements of an array
In this topic, we are going to learn how to print integer array elements in C++ programming language using for, while and do-while loops.
In this blog, We have already discuss that “What is an array“, type of arrays and how to access it(one dim, two dim and three dim arrays)
Arrays are the special type of variables to store Multiple type of values(int, string,char, etc)under the same name in the continuous memory location. we can be easily accessed using the indices(indexes)
Here,
In this program, we are briefing print array of integers using for loop in C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { int arr[6]={21,32,45,57,65,78}; cout << "Array elements of given array" << endl; for(int i=0; i<6; i++){ cout<<arr[i]<<" "; } getch(); return 0; }
When the above code is executed, it produces the following result
Array elements of given array 21 32 45 57 65 78
In this program, we are briefing print array of integers using for loop in C++ language
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { int arr[6]; arr[0]=43; arr[1]=51; arr[2]=57; arr[3]=75; arr[4]=89; arr[5]=98; cout << "Array elements of given array" << endl; for(int i=0; i<6; i++){ cout<<arr[i]<<" "; } getch(); return 0; }
When the above code is executed, it produces the following result
Array elements of given array 43 51 57 76 89 98
In this program, we are briefing print array of integers using while loop in C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { int arr[6]={210,302,458,577,635,678}; cout << "Array elements of given array" << endl; int i=0; while(i<6){ cout<<arr[i]<<" "; i++; } getch(); return 0; }
When the above code is executed, it produces the following result
Array elements of given array 210 302 458 577 635 678
In this program, we are briefing print array of integers using while loop in C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { int arr[6]; arr[0]=100; arr[1]=90; arr[2]=80; arr[3]=70; arr[4]=60; arr[5]=50; cout << "Array elements of given array" << endl; int i=0; while(i<6){ cout<<arr[i]<<" "; i++; } getch(); return 0; }
When the above code is executed, it produces the following result
Array elements of given array 100 90 80 70 60 50
In this program, we are briefing print array of integers using do-while loop loop in C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { int arr[6]; arr[0]=1001; arr[1]=902; arr[2]=803; arr[3]=704; arr[4]=605; arr[5]=506; cout << "Array elements of given array" << endl; int i=0; do{ cout<<arr[i]<<" "; i++; } while(i<6); getch(); return 0; }
When the above code is executed, it produces the following result
Array elements of given array 1001 902 803 704 605 506
In this program, we are briefing print array of integers using do-while loop in C++ language
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { int arr[6]={111,222,333,444,555,666}; cout << "Array elements of given array" << endl; int i=0; do{ cout<<arr[i]<<" "; i++; } while(i<6); getch(); return 0; }
When the above code is executed, it produces the following result
Array elements of given array 111 222 333 444 555 666
Similar post
Code to read and print integers of an array in Java
Code to read and print strings of an array in Java
Code to read and print characters of an array in Java
Code to read and print integers of an array in C++
Code to read and print strings of an array in C++
Code to read and print characters of an array in C++
Code to read and print integers of an array in C
Code to read and print strings of an array in C
Suggested for you
One dimensional array in C language
One dimensional array in C++ language
Two dimension array in Java language
Two dimension array in C language
Two dimension array in C++ language
Three dimension array in Java language
Three dimension array in C language
Three dimension array in C++ language
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…