Software Development Exam  >  Software Development Notes  >  Basics of C++  >  Code: Hollow Diamond Pattern

Code: Hollow Diamond Pattern | Basics of C++ - Software Development PDF Download

Code: Hollow Diamond Pattern | Basics of C++ - Software Development

C++ Program for Hollow Diamond Pattern

#include<iostream>

using namespace std;

void hollowDiamond(int n) {


  for (int i = 0; i < n; i++) {

    for (int j = 0; j < (2 * n); j++) {

      if (i + j <= n - 1) // upper left triangle

        cout << "*";

      else

        cout << " ";

      if ((i + n) <= j) // upper right triangle

        cout << "*";

      else

        cout << " ";

    }

    cout << "\n";

  }

  // bottom half of the pattern

  for (int i = 0; i < n; i++) {

    for (int j = 0; j < (2 * n); j++) {

      if (i >= j) // bottom left triangle

        cout << "*";

      else

        cout << " ";

      if (i >= ((2 * n) - 1) - j) // bottom right triangle

        cout << "*";

      else

        cout << " ";

    }

    cout << "\n";

  }

}

int main() {

  int num;

  cout << "Enter number of levels of the pattern :" << endl;

  cin >> num;

  hollowDiamond(num);

  return 0;

}

The document Code: Hollow Diamond Pattern | Basics of C++ - Software Development is a part of the Software Development Course Basics of C++.
All you need of Software Development at this link: Software Development
70 videos|45 docs|15 tests

Top Courses for Software Development

70 videos|45 docs|15 tests
Download as PDF
Explore Courses for Software Development exam

Top Courses for Software Development

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

video lectures

,

Free

,

mock tests for examination

,

practice quizzes

,

past year papers

,

Important questions

,

Previous Year Questions with Solutions

,

Exam

,

Code: Hollow Diamond Pattern | Basics of C++ - Software Development

,

shortcuts and tricks

,

Viva Questions

,

ppt

,

Extra Questions

,

Sample Paper

,

Objective type Questions

,

study material

,

MCQs

,

Summary

,

pdf

,

Semester Notes

,

Code: Hollow Diamond Pattern | Basics of C++ - Software Development

,

Code: Hollow Diamond Pattern | Basics of C++ - Software Development

;