#include<iostream.h>
#include<conio.h>
void main()
{
int j,i,k,l;
char c;
clrscr();
do
{
cout<<"Enter the number of stars in the base..";
cin>>k;
for (i=1;i<=k;i++)
{
for (j=1;j<=i;j++)
cout<<"* ";
cout<<endl;
}
cout<<"\nWant to try more..(y/n)\n";
cin>>c;
}
while(c=='y');
getch();
}
A blog containing C++ programs based on Classes, Objects and related concepts like Inheritance, Polymorphism etc.
Showing posts with label PATTERN. Show all posts
Showing posts with label PATTERN. Show all posts
Monday, December 7, 2020
C++ program to print an lower triangle using stars.
Tuesday, September 11, 2012
EQUILATERAL TRIANGLE USING STARS
C++ program to print an equilateral triangle using stars.
#include<iostream.h>
#include<conio.h>
void main()
{
int j,i,k,l;
char c;
clrscr();
do
{
cout<<"Enter the number of stars in the base..";
cin>>k;
for (i=1;i<=k;i++)
{
for(l=0;l<(k-i);l++)
cout<<" ";
for (j=0;j<i;j++)
cout<<"* ";
cout<<endl;
}
cout<<"\nWant to try more..(y/n)\n";
cin>>c;
}
while(c=='y');
getch();
}
OUTPUT
#include<iostream.h>
#include<conio.h>
void main()
{
int j,i,k,l;
char c;
clrscr();
do
{
cout<<"Enter the number of stars in the base..";
cin>>k;
for (i=1;i<=k;i++)
{
for(l=0;l<(k-i);l++)
cout<<" ";
for (j=0;j<i;j++)
cout<<"* ";
cout<<endl;
}
cout<<"\nWant to try more..(y/n)\n";
cin>>c;
}
while(c=='y');
getch();
}
OUTPUT
Monday, August 13, 2012
PROGRAM TO PRINT A DIAMOND IN A BOX - 2
C++ program to print a diamond inside a box using asterisks.
output
You may also like:
C++ program to print a diamond in a box - 1
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j,x,n=1,t=1,l;
clrscr();
cout<<"Enter limit\n";
cin>>l;
x=l/2;
for(i=0;i<l;i++)
{
for(j=0;j<l;j++)
{
if(i>0&&i<(l-1))
{
if(j>=x&&n>0)
{
cout<<"*";
n-=1;
}
else if(i==0||i==(l-1)||j==0||j==(l-1))
{
cout<<"*";
}
else
{
cout<<" ";
}
}
else
{
if(i==0||i==(l-1))
{
cout<<"*";
}
}
}
if(i>0&&i<(l/2))
{
t=t+2;
n=t;
x-=1;
}
else
{
t=t-2;
n=t;
x+=1;
}
cout<<endl;
}
getch();
}
#include<conio.h>
void main()
{
int i,j,x,n=1,t=1,l;
clrscr();
cout<<"Enter limit\n";
cin>>l;
x=l/2;
for(i=0;i<l;i++)
{
for(j=0;j<l;j++)
{
if(i>0&&i<(l-1))
{
if(j>=x&&n>0)
{
cout<<"*";
n-=1;
}
else if(i==0||i==(l-1)||j==0||j==(l-1))
{
cout<<"*";
}
else
{
cout<<" ";
}
}
else
{
if(i==0||i==(l-1))
{
cout<<"*";
}
}
}
if(i>0&&i<(l/2))
{
t=t+2;
n=t;
x-=1;
}
else
{
t=t-2;
n=t;
x+=1;
}
cout<<endl;
}
getch();
}
output
You may also like:
C++ program to print a diamond in a box - 1
PROGRAM TO PRINT A DIAMOND IN A BOX - 1
C++ program to print a diamond inside a box using asterisks.
output
You may also like:
C++ program to print a diamond inside a box using asterisks.
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
int i=0,j=0,num;
clrscr();
cout<<"Enter limit\n";
cin>>num;
cout<<endl;
for(i=-(num+2);i<=num+2;i++)
{
for(j=-(num+2);j<=num+2;j++)
{
if(abs(i)+abs(j)<=num||j==-(num+2)
||j==(num+2)||i==-(num+2)||i==(num+2))
{
cout<<"*";
}
else
{
cout<<" ";
}
}
cout<<endl;
}
getch();
}
#include<conio.h>
#include<math.h>
void main()
{
int i=0,j=0,num;
clrscr();
cout<<"Enter limit\n";
cin>>num;
cout<<endl;
for(i=-(num+2);i<=num+2;i++)
{
for(j=-(num+2);j<=num+2;j++)
{
if(abs(i)+abs(j)<=num||j==-(num+2)
||j==(num+2)||i==-(num+2)||i==(num+2))
{
cout<<"*";
}
else
{
cout<<" ";
}
}
cout<<endl;
}
getch();
}
output
You may also like:
C++ program to print a diamond inside a box using asterisks.
Subscribe to:
Posts (Atom)