Table of Contents
In this article, we will discuss the concept of C++ program to print n elements in one dim array
In this post, we are going to learn how to write a program to print integer in an array in C++ language using for, while and do-while loop
In this code, we are going to learn how to print integer elements in single dimensional array using for loop in C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { int arr[25,78,90,54,67,91}; cout << "Array elements of given array" << endl; for(int i=0; i<6; i++){ cout<<arr[i]<<" "; } getch(); return 0; }
When the code is executed, it produces the following result
Array elements of given array 25 78 90 54 67 91
In this code, we are going to learn how to print integer elements in single dimensional array using for loop in C++ language
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { int arr[6]; cout << "Enter elements of the array" << endl; for(int i=0; i<6; i++){ cin>>arr[i]; } cout << "\nArray elements of given array" << endl; for(int i=0; i<6; i++){ cout<<"element of arr["<<i<<"]:"; cout<<arr[i]<<" "; cout<<"\n"; } getch(); return 0; }
When the code is executed, it produces the following result
Enter elements of the array 36 87 80 98 68 72 Array elements of given array Element of arr[0]: 36 Element of arr[1]: 87 Element of arr[2]: 80 Element of arr[3]: 98 Element of arr[4]: 68 Element of arr[5]: 72
In this code, we are going to learn how to print integer elements in single dimensional array using while loop in C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { int arr[6]{250,780,900,540,670,910}; cout << "Array elements of given array" << endl; int i=0; while( i<6){ cout<<arr[i]<<" "; i++; } getch(); return 0; }
When the code is executed, it produces the following result
Array elements of given array 250 780 900 540 670 910
In this code, we are going to learn how to print integer elements in single dimensional array using while loop in C++ language
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { int arr[6]; cout << "Enter elements of the array" << endl; int i=0; while(i<6){ cin>>arr[i]; i++; } cout << "\nArray elements of given array" << endl; i=0; while( i<6){ cout<<"Display elemnt of arr["<<i<<"]:"; cout<<arr[i]<<" "; cout<<"\n"; i++; } getch(); return 0; }
When the code is executed, it produces the following result
Enter elements of the array 122 233 344 455 566 677 Array elements of given array Element of arr[0]: 122 Element of arr[1]: 233 Element of arr[2]: 344 Element of arr[3]: 455 Element of arr[4]: 566 Element of arr[5]: 677
In this code, we are going to learn how to print integer elements in single dimensional array using do-while loop in C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { int arr[6]{50,80,90,40,70,10}; cout << "Array elements of given array" << endl; int i=0; do{ cout<<arr[i]<<" "; i++; }while( i<6); getch(); return 0; }
When the code is executed, it produces the following result
Array elements of given array 50 80 90 40 70 10
In this code, we are going to learn how to print integer elements in single dimensional array using do- while loop in C++ language
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { int arr[6]; cout << "Enter elements of the array" << endl; int i=0; do{ cin>>arr[i]; i++; }while(i<6); cout << "\nArray elements of given array" << endl; i=0; do{ cout<<"Display elemnt of arr["<<i<<"]:"; cout<<arr[i]<<" "; cout<<"\n"; i++; }while( i<6); getch(); return 0; }
When the code is executed, it produces the following result
Enter elements of the array 4 7 9 3 5 6 Array elements of given array Element of arr[0]: 4 Element of arr[1]: 7 Element of arr[2]: 9 Element of arr[3]: 3 Element of arr[4]: 5 Element of arr[5]: 6
Suggested for you
Variable in C language
Data type in C language
One dimensional array in C language
Variable in C++ language
Data type in C++ language
One dimensional array in C++ language
Do-while loop in Java language
Similar post
Java program to read and print array elements using for loop
Java program to read and print array elements using while loop
Java program to read and print array elements using Do-while loop
C code to take and print array elements using for loop
C code to take and print array elements using while loop
C code to take and print array elements using do-while loop
C++ program to read and print array elements using for loop
C++ program to read and print array elements using while loop
C++ program to read and print array elements using do-while loop
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.