You are on page 1of 10

1.#include<iostream.

h>
#include<conio.h>
void main()
{
clrscr();
int i, j, k=8;
for(i=0; i<5; i++)
{
for(j=0; j<k; j++)
{
cout<<" ";}
k=k-2;
for(j=0; j<=i; j++)
{cout<<"* ";
}
cout<<"\n";
}
getch();
}

When the above C++ program is compile and executed, it will produce the
following result:
2. #include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i, j, n=1;
for(i=0; i<5; i++)
{
for(j=0; j<=i; j++)
{
cout<<n<<" ";
n++;
}
cout<<"\n";
}
getch();
}

When the above C++ program is compile and executed, it will produce the
following result:
3. #include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i, j, num;
for(i=0; i<5; i++)
{
num=1;
for(j=0; j<=i; j++)
{
cout<<num<<" ";
num++;
}
cout<<"\n";
}
getch();
}

When the above C++ program is compile and executed, it will produce the
following output (half pyramid using numbers):

4. #include <iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i, space, rows, k=0;
cout<<"Enter the number of rows : ";
cin>>rows;
for(i=1; i<=rows; i++)
{
for(space=1; space<=(rows-i); space++)
{
cout<<" ";
}
while(k!=(2*i-1))
{
cout<<"* ";
k++;
}
k=0;
cout<<"\n";
}
getch();
}

When the above C++ program is compile and executed, it will produce the
following output (pyramid of stars):

5.Print half pyramid using continuous characters starting from 'A'.


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i, j;
char ch='A';
for(i=0; i<5; i++)
{
for(j=0; j<=i; j++)
{
cout<<ch<<" ";
ch++;
}
cout<<"\n";
}
getch();
}

When the above C++ program is compile and run, it will produce the following
output:
6.#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i, j;
char ch='A';
for(i=0; i<5; i++)
{
for(j=0; j<=i; j++)
{
cout<<ch<<" ";
}
cout<<"\n";
ch++;
}
getch();
}

When the above C++ program is compile and executed, it will produce the
following output (half pyramid using characters):

7.#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i, j;
for(i=0; i<5; i++)
{
for(j=5; j>i; j--)
{
cout<<"* ";
}
cout<<"\n";
}
getch();
}

When the above C++ program is compile and executed, it will produce the
following output (inverted half pyramid using stars):

8.#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i, j, num=1;
for(i=0; i<5; i++)
{
for(j=5; j>i; j--)
{
cout<<num<<" ";
num++;
}
cout<<"\n";
num=1;
}
getch();
}

When the above C++ program is compile and run, it will produce the following
output (inverted half pyramid using numbers):
9.#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i, j, k, decr=8, count=64, temp;
char ch='A';
for(i=0; i<5; i++)
{
for(k=0; k<decr; k++)
{
cout<<" ";
}
for(j=0; j<i+1; j++)
{
count++;
}
ch = count;
temp = ch;
for(j=0; j<i+1; j++)
{
cout<<ch--<<" ";
}
cout<<"\n";
ch = temp;
decr=decr-2;
}
getch();
}

Here sample run given of this C++ program:


10. This C++ program prints the alphabet
* patterns on the screen */

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i, j, incr=1;
char ch = 'A';
for(i=0; i<5; i++)
{
for(j=0; j<incr; j++)
{
cout<<ch<<" ";
ch++;
}
cout<<"\n";
incr = incr + 2;
}
getch();
}

Below is the sample run of this C++ program :

You might also like