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

mock tests for examination

,

Previous Year Questions with Solutions

,

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

,

Exam

,

Important questions

,

practice quizzes

,

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

,

Viva Questions

,

Free

,

video lectures

,

past year papers

,

Extra Questions

,

Objective type Questions

,

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

,

pdf

,

ppt

,

study material

,

shortcuts and tricks

,

Semester Notes

,

Sample Paper

,

MCQs

,

Summary

;