Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
C++ code to print array using for loop

C++ print all element in array using do-while loop

Posted on October 31, 2021October 31, 2021

Table of Contents

  • C++ print all element in array using do-while loop
    • Code to Display array elements
      • Program to print integers of an array using do-while loop – #1
      • Program to print integers of an array using do-while loop – #2
      • Program to print Strings of an array using do-while loop – #1
      • Program to print Strings of an array using do-while loop – #2
      • Program to print characters of an array using do-while loop – #1
      • Program to print characters of an array using do-while loop – #2

C++ print all element in array using do-while loop

In this article, we will discuss the concept of C++ print all element in array using do-while loop

In this post, we are going to learn how to write a program to  print in an array using do-while loop in C++ language

Code to Display array elements

Program to print integers of an array using do-while loop – #1

In this code, we are going to learn how to display array of  integers using do-while loop in C++ language

Program 1

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int marks[5];
    marks[0]=98;
    marks[1]=65;
    marks[2]=54;
    marks[3]=71;
    marks[4]=75;
cout <<"Marks are: ";
    int i=0;
    do{
        cout<< marks[i] << endl;
        i++;
    }while( i<5);
getch();
    return 0;
}

When the above code is executed, it produces the following result

Marks are: 98

65
54
71
75

 

 

Program to print integers of an array using do-while loop – #2

In this code, we are going to learn how to display array of  integers using do-while loop in C++ language

Program 2

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int num[]{567,943,245,678,988};
  /*  marks[0]=98;
    marks[1]=65;
    marks[2]=54;
    marks[3]=71;
    marks[4]=75;*/
cout <<"Numbers of Array : ";
    int i=0;
    do{
        cout<< num[i] << endl;
        i++;
    }while( i<5);
getch();
    return 0;
}

When the above code is executed, it produces the following result

Numbers of Array: 567

943
245
678
988

 

Program to print Strings of an array using do-while loop – #1

In this code, we are going to learn how to display array of  Strings using do-while loop in C++ language

Program 1

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    string str[20]={"Soisa","Mugtha","Manchu","Malar","Ponna"};
    //Single one D array declaration and initialization

    cout<<"\nStudents names are:\n";
    int i=0;
    do{
            cout<<" str=["<<i<<"]: ";
        cout<<str[i]<<"\n";
        //Display the students name
        i++;
    }while( i<5);
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Students names are:

str[0]: Soisa
str[1]: Mugtha
str[2]: Manchu
str[3]: Malar
str[4]: Ponna

 

 

Program to print Strings of an array using do-while loop – #2

In this code, we are going to learn how to display array of  Strings using do-while loop in C++ language

Program 2

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
   // string str[20]={"Soisa","Mugtha","Manchu","Malar","Ponna"};
    //Single one D array declaration and initialization
    string str[20];

    str[0]= "Pooja";
str[1]= "Majaa";
str[2]= "Punitha";
str[3]= "Kaja";
str[4]= "Nisha";


    cout<<"\nStudents names are:\n";
    int i=0;
    do{
            cout<<" str=["<<i<<"]: ";
        cout<<str[i]<<"\n";
        //Display the students name
        i++;
    }while( i<5);
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Students names are:

str[0]: Pojaa
str[1]: Majaa
str[2]: Punitha
str[3]: Kaja
str[4]: Nisha

 

 

 

Program to print characters of an array using do-while loop – #1

In this code, we are going to learn how to display array of  characters using do-while loop in C++ language

Program 1

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int i;

    char char_arr[7];
//Array declaration - char array

char_arr[0]='e';
char_arr[1]='l';
char_arr[2]='e';
char_arr[3]='m';
char_arr[4]='e';
char_arr[5]='n';
char_arr[6]='t';
//array initialization

//display array of characters using do-while loop
    cout<<"\ndisplay the characters\n";
    i=0;
      do{//display elements using for loop
      cout<<"char_arr["<<i<<"]:"<<char_arr[i];
      cout<<("\n");
       i++;
    }while(i<7);
getch();
    return 0;
}

When the above code is executed, it produces the following result

display the characters:

char_arr[0]:e
char_arr[1]:l
char_arr[2]:e
char_arr[3]:m
char_arr[4]:e
char_arr[5]:n
char_arr[6]:t


Program to print characters of an array using do-while loop – #2

In this code, we are going to learn how to display array of  characters using do-while loop in C++ language

Program 2

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int i;

    char char_arr[4]={'C','o','m','e'};
//Array declaration - char array

/*char_arr[0]='e';
char_arr[1]='l';
char_arr[2]='e';
char_arr[3]='m';
char_arr[4]='e';
char_arr[5]='n';
char_arr[6]='t';
//array initialization
*/
//display array of characters using do-while loop
    cout<<"\ndisplay the characters\n";
    i=0;
      do{//display elements using for loop
      cout<<"char_arr["<<i<<"]:"<<char_arr[i];
      cout<<("\n");
       i++;
    }while(i<4);
getch();
    return 0;
}

When the above code is executed, it produces the following result

display the characters:

char_arr[0]:C
char_arr[1]:o
char_arr[2]:m
char_arr[3]:e


Suggested for you

For loop in C++ language

while loop in C++ language

do-while loop in C++ language

Operator in C++ language

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

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes