EmSAT Achieve Exam  >  EmSAT Achieve Notes  >  C++ for EmSAT Achieve  >  Code: Hollow Diamond Pattern

Code: Hollow Diamond Pattern | C++ for EmSAT Achieve PDF Download

Code: Hollow Diamond Pattern | C++ for EmSAT Achieve

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 | C++ for EmSAT Achieve is a part of the EmSAT Achieve Course C++ for EmSAT Achieve.
All you need of EmSAT Achieve at this link: EmSAT Achieve
70 videos|45 docs|15 tests

Top Courses for EmSAT Achieve

70 videos|45 docs|15 tests
Download as PDF
Explore Courses for EmSAT Achieve exam

Top Courses for EmSAT Achieve

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

study material

,

video lectures

,

Extra Questions

,

past year papers

,

Exam

,

Semester Notes

,

shortcuts and tricks

,

Previous Year Questions with Solutions

,

Important questions

,

Code: Hollow Diamond Pattern | C++ for EmSAT Achieve

,

mock tests for examination

,

MCQs

,

Free

,

practice quizzes

,

Objective type Questions

,

Code: Hollow Diamond Pattern | C++ for EmSAT Achieve

,

pdf

,

Summary

,

ppt

,

Code: Hollow Diamond Pattern | C++ for EmSAT Achieve

,

Viva Questions

,

Sample Paper

;