badge

C++ program to implement DIAMOND PATTERN

Program in c++ for DIAMOND PATTERM...

DESCRIPTION:- This program generally will give output of the program of a diamond shape pattern. whatever value u wiil give it prints a diamond shape pattern. simple funda is used . just took a  for loop for(int k=0;k<((2*i)+1);k++) basically this loop is main which helps to print the diamond shape pattern.




OUTPUT OF THE PROGRAM


SOURCE CODE:-

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


using namespace std;
static int z=1;


void pattern(int n)
{
static int i=0;
if(n>=0)
{
 
for(int j=n;j>0;j--)
{
cout<<" ";
}

for(int k=0;k<((2*i)+1);k++)
{
cout<<"*";
}

cout<<"\n";
z++;
n--;
i++;
pattern(n);
}
}




void pattern1(int n)
{
static int y=z-2;
static int i=n+1;
if(n>=0)
{
 
    for(int j=i;j>n;j--)
    {
    cout<<" ";
    }
    for(int k=((2*n)+1);k>0;k--)
    {
        cout<<"*";
     
    }
    cout<<"\n";

n--;
y--;
pattern1(n);

}
}

int main()
{
int n;
cout<<"\nEnter value:";
cin>>n;
pattern(n);
pattern1(n-1);


getch();
}




/* IF U FOUND ANY PROBLEM IN THIS PROGRAM  OR IF YOU HAVE ANY QUERY RELATED THIS PROGRAM THEN PLEASE COMMENT IN THIS POST OR YOU CAN DIRECTLY MAIL ME ON piyushkhandelwal029@gmail.com . */

THANKU.

SHARE

Admin

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments: