0% found this document useful (0 votes)
6 views2 pages

Do While Loop

Uploaded by

jctbautista23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Do While Loop

Uploaded by

jctbautista23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

using namespace std;

int main() {
int n;

// First do while loop


// Input size
do {
cout << "Enter the size of the diamond (positive integer): ";
cin >> n;
} while (n <= 0);

int spaces = n - 1, stars = 1;

// Second do while loop


//Upper half of the diamond
do {
// Print spaces
int i = 0;
do {
cout << " ";
i++;
} while (i < spaces);

// Print stars
int j = 0;
do {
cout << "*";
j++;
} while (j < stars);

cout << endl;


spaces--;
stars += 2;
} while (spaces >= 0);

spaces = 1, stars = 2 * n - 3;

// Third do while loop


// Lower half of the diamond
do {
// Print spaces
int i = 0;
do {
cout << " ";
i++;
} while (i < spaces);

// Print stars
int j = 0;
do {
cout << "*";
j++;
} while (j < stars);

cout << endl;


spaces++;
stars -= 2;
} while (stars > 0);

return 0;
}

You might also like