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();
}
/*
THANKU.
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();
}
/*
THANKU.
0 comments:
Post a Comment