Table of Contents
In this article, we will discuss the concept of C++ program to accept array input and print using Do-While loop
In this post, we are going to learn how to write a program to read array input and print given elements in an array using do-while loop in C++ language
In this code, we are going to learn how to read integer array input given by user and print the them using do-while loop in C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { int i,len;//integer variable declaration cout<<"Enter the Array length: "; //Ask input for array length cin>>len; //Reading the input for array length int num[len]; //Array declaration - one dimension cout<<"\n";//move to next line cout<<"Enter the Number for array :"; //Ask input for elements(marks) i=0; do{//takes input using for loop cin>>num[i]; //Reading the array elements from user i++; }while(i<len); cout<<"\ndisplay the number\n"; i=0; do{//display elements using do-while loop cout<<num[i]; cout<<("\n"); i++; }while(i<len); getch(); return 0; }
When the above code is executed, it produces the following result
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { int i,len;//Variable declaration-integer cout<<"Enter the Array length: "; //Ask input for array length cin>>len; //Reading the input for array length int num[len]; //Array declaration cout<<"\n";//move to next line i=0; //Ask input for elements(number) do{//input using do-while loop cout<<"Enter the numbers "<<"num["<<i<<"] :"; cin>>num[i]; //Reading the array elements from user i++; }while( i<len); cout<<"\ndisplay the numbers\n"; i=0; do{//display elements using do-while loop cout<<"num["<<i<<"] :"<<num[i]; cout<<("\n"); i++; }while(i<len); getch(); return 0; }
When the above code is executed, it produces the following result
Enter the array length: 4 Enter the numbers num[0]: 6357 Enter the numbers num[1]: 8347 Enter the numbers num[2]: 9123 Enter the numbers num[3]: 4556 Display the numbers num[0]=6357 num[1]: 8347 num[2]: 9123 num[3]: 4556
In this code, we are going to learn how to read string array input given by user and print the them using do-while loop in C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { string str[20]; int len; cout<<"Enter array length\n"; cin>>len; cout<<"\nEnter students name\n"; int i=0; do{ cin>>str[i]; i++; }while(i<len); cout<<"\nEntered students names are:\n"; int j=0; do{ cout<<str[j]<<"\n"; j++; }while(j<len); getch(); return 0; }
When the above code is executed, it produces the following result
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { string str[20]; int len; cout<<"Enter array length\n"; cin>>len; cout<<"\nEnter students name\n"; int i=0; do{ cout<<"Enter the string"<<" str=["<<i<<"]: "; cin>>str[i]; i++; }while(i<len); cout<<"\nEntered students names are:\n"; int j=0; do{ cout<<"Your entered string is:"<<" str=["<<j<<"]: "; cout<<str[j]<<"\n"; j++; }while(j<len); getch(); return 0; }
When the above code is executed, it produces the following result
In this code, we are going to learn how to read character array input given by user and print the them using do-while loop in C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { int i,len; //variable declaration for integer cout<<"Enter the Array length: "; //Request input for array length cin>>len; //Reading the input for array length char char_array[len]; //character Array declaration cout<<"\n";//move to next line cout<<"Enter the characters for array :"; //Request input for elements(numbers) i=0; do{//input using for loop cin>>char_array[i]; //Reading the array elements from user i++; }while(i<len); cout<<"\ndisplay the characters\n"; i=0; do{//display elements using for loop cout<<char_array[i]; cout<<("\n"); i++; } while(i<len); getch(); return 0; }
When the above code is executed, it produces the following result
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { int i,len; //variable declaration for integer cout<<"Enter the Array length: "; //Request input for array length cin>>len; //Reading the input for array length char char_array[len]; //Array declaration cout<<"\n";//move to next line cout<<"Enter the characters for array :\n"; //Request input for elements(numbers) i=0; do{//input using for loop cout<<"char_array["<<i<<"]:"; cin>>char_array[i]; //Reading the array elements from user i++; }while(i<len); cout<<"\ndisplay the characters\n"; i=0; do{//display elements using for loop cout<<"char_array["<<i<<"]:"<<char_array[i]; cout<<("\n"); i++; }while(i<len); getch(); return 0; }
When the above code is executed, it produces the following result
Suggested for you
One dimensional array in C++ language
Hollow world program in C++ 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 read and print array elements using for loop
C code to read and print array elements using while loop
C code to read 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.