Skip to content
Programming101
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programmingoneonone

C++ program to print diamond pattern of stars

YASH PAL, 31 July 202422 August 2024

In this post, we will write a C++ program to print the diamond patterns of stars. the first user will enter the number between 1 to 25 and then the program will print the star pattern based on the number.

C++ program to print diamond pattern of stars

C++ program to print diamond patterns of stars

#include<iostream>
#include<conio.h>
#include<windows.h>

BOOL gotoxy(const WORD x, const WORD y) {
    COORD xy;
    xy.X = x;
    xy.Y = y;
    return SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), xy);
}

int main()
{
    system("cls");

    int i,j,k,l,n;

    std::cout<<"Enter the number of star b/w 1 to 25 = ";
    std::cin>>n;

system("cls");

    if(n <= 25)
    {
        for(i=1;i<=n;i++)
            for(j=(n+1)-i;j<=i;j++)
            {
                gotoxy(i+i-n,j);
                std::cout<<"*";
            }

        for(k=n;k>=1;k--)
            for(l=k;l<=(n+1)-k;l++)
            {
                gotoxy(k+k+(n-2),l);
                std::cout<<"*";
            }
    }
    else
        std::cout<<"The number you enter is greater than 25 ";

    getch();
    return 0;
}

Output

Enter the number of star b/w 1 to 25 = 25

                  *
                * * *
              * * * * *
            * * * * * * *
          * * * * * * * * *
        * * * * * * * * * * *
      * * * * * * * * * * * * *
    * * * * * * * * * * * * * * *
      * * * * * * * * * * * * *
        * * * * * * * * * * *
          * * * * * * * * *
            * * * * * * *
              * * * * *
                * * *
                  *
C++ Programming Tutorials coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes