Showing posts with label C. Show all posts
Showing posts with label C. Show all posts

Friday, 24 October 2014

Star Pattern Programs Cplusplus

Program To Print Following Star Pattern in Cpluplus


Star Pattern in Cpluplus


#include<iostream.h>
void main()
{
   int i,j,k,n;
   cout<<"\Enter the number of lines to be printed: ";
    cin>>n;
   for(i=0;i<n;i++)
   {
      for(j=0;j<(n-i-1);j++)
 cout<<" ";
      for(k=0;k<(2*i+1);k++)
 cout<<"*";
      cout<<endl;
   }
      for(i=0;i<n-1;i++)
   {
      for(j=0;j<=i;j++)
cout<<" ";
      for(k=(2*n-2*i-3);k>0;k--)
   cout<<"*";
      cout<<endl;
   }
}

 

Program To Print Following Star Pattern in Cpluplus

Star Pattern in Cpluplus

Star Pattern in Cpluplus



#include<iostream.h>
void main()
{
 int i,j,k,n;
 cout<<"\Enter the number of lines to be printed: ";
 cin>>n;
 for(i=0;i<n;i++)
 {
       for(j=n-i-1;j>0;j--)
     cout<<" ";
       cout<<"*";
       for(k=2*i-1;k>0;k--)
     cout<<" ";             //code for upper triangle
       if(i!=0)
     cout<<"*";
       cout<<endl;
  }
  for(i=n-1;i>0;i--)
  {
       for(j=0;j<n-i;j++)
     cout<<" ";
       cout<<"*";                  //code for lower triangle
for(k=2*i-3;k>0;k--)
    cout<<" ";
       if(i!=1)
     cout<<"*";
       cout<<"\n";
    }
}

 

Program To Create Circular Loading Bar using Graphics.h


#include<graphics.h>

#include<dos.h>

void main()
{
int gd=DETECT,gm; 
              // variable to detect graphics driver and graphic mode

 int counter;   

//Below is code to initialize the graphics with parameters for graphics initgraph(&gd,&gm,"c:\\turboc3\\bgi");

//Loop to show the loading circle for(counter=0;counter<=360;++counter)
{
circle(300,200,80);
pieslice(300,200,0,counter,80);
outtextxy(200,320,"Loading....Please Wait!");
delay(20);
}
closegraph();
}

OUTPUT :
Program To Create Circular Loading Bar graphics.h cplusplus
Program To Create Circular Loading Bar graphics.h cplusplus




Program To Create Loading Bar using Graphics.h


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

void main()
{
 int x=170,i,gdriver=DETECT,gmode;
  // variable to detect graphics driver and graphic mode

//Below is code to initialize the graphics with parameters for graphics
 initgraph(&gdriver,&gmode,"c:\\tc\\bgi");

 settextstyle(DEFAULT_FONT,HORIZ_DIR,2);

//Outtextxy is used to print the given text at specified x and y pixel position 
//It will print given text at pixel position 170,180
 outtextxy(170,180,"LOADING,PLEASE WAIT");

  for(i=0;i<300;++i)
 {
  delay(30);
  line(x,200,x,220);
  x++;
 }
 getch();

//close the graph that was initialized
 closegraph();  

}

OUTPUT :
Program To Create Loading Bar using Graphics.h Cplusplus
Program To Create Loading Bar using Graphics.h Cplusplus


Program To Print Star Triangle Pattern in Cplusplus


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

void main()
{
clrscr(); //to clear the screen
int i,j,k,num;

cout<<"Tell How many lines you want";
cin>>num;

num*=2;
for(i=0;i<num;i+=2)
{
cout<<"\n";

for ( j = num; j > i; j -= 2 )
cout<<" ";

for( k=0; k<=i; ++k )
cout<<"*";
}
getch(); //to stop the screen
}
OUTPUT


Program To Print Star Triangle Pattern Cplusplus
Program To Print Star Triangle Pattern Cplusplus

Program To Print Alphabets in Cplusplus ( I have printed A to H ) 


#include<iostream>

using namespace std;

int main()
{
int i,j,k=1;
char ch;
cout<<"Input an Alphabet in capital letters that you want to print:";
cin>>ch;
cout<<"\n\n\n\n";
switch(ch)
{
case 'A':
cout<<"\t\t\t    ";
for(i=1;i<=40;++i)
{
for(j=0;j<=22;++j)
{
if(i==1||i==2||i==21||i==20)
cout<<"*";
else
{
if(j==0||j==20)
cout<<"**";
else
cout<<" ";
}
}
cout<<"\n\t\t\t    ";

}
break;



case 'B':
cout<<"\t\t\t\t";

while(k<=2)
{
for(i=1;i<=9;++i)
{
for(j=0;j<=i;++j)
{
if(j==0||j==i)
cout<<"**";
else
cout<<" ";
}

cout<<"\n\t\t\t\t";

}
for(i=1;i<=10;++i)
{
if(i==1||i==10)
cout<<"**";
else
cout<<" ";
}
cout<<"\n\t\t\t\t";

for(i=1;i<=10;++i)
{
if(i==1||i==10)
cout<<"**";
else
cout<<" ";
}
cout<<"\n\t\t\t\t";

for(i=9;i>=1;--i)
{
for(j=0;j<=i;++j)
{
if(j==0||j==i)
cout<<"**";
else
cout<<" ";
}
cout<<"\n\t\t\t\t";
}
++k;
}
 break;

 case'C':
cout<<"\t\t\t    ";

for(i=1;i<=40;++i)
{
for(j=0;j<=22;++j)
{
if(i==1||i==2||i==39||i==40)
cout<<"*";
else
{
if(j==0)
cout<<"**";
else
cout<<" ";
}
}
cout<<"\n\t\t\t    ";

}
break;

 case'D':
 cout<<"\t\t\t\t";
 for(i=1;i<=18;++i)
 {
for(j=0;j<=i;++j)
{
if(j==0||j==i)
cout<<"**";
else
cout<<" ";
}
cout<<"\n\t\t\t\t";
 }
 while(k<=4)
 {
for(i=1;i<=19;++i)
{
if(i==1||i==19)
cout<<"**";
else
cout<<" ";
}
cout<<"\n\t\t\t\t";
 ++k;
 }
 for(i=18;i>=1;--i)
 {
for(j=0;j<=i;++j)
{
if(j==0||j==i)
cout<<"**";
else
cout<<" ";
}
 cout<<"\n\t\t\t\t";
 }
 break;

 case'E':

 cout<<"\t\t\t\t";
 for(i=1;i<=39;++i)
 {
for(j=1;j<=20;++j)
{
if(i==1||i==2||i==20||i==21||i==38||i==39)
cout<<"*";
else
{
if(j==1)
cout<<"**";
else
cout<<" ";
}
}
 cout<<"\n\t\t\t\t";
 }
 break;

 case'F':

 cout<<"\t\t\t\t";

for(i=1;i<=40;++i)
{
for(j=1;j<=20;++j)
{
if(i==1||i==2||i==18||i==19)
cout<<"*";
else
{
if(j==1)
cout<<"**";
else
cout<<" ";
}
}
cout<<"\n\t\t\t\t";
}
break;

 case'G':

cout<<"\t\t\t";
for(i=1;i<=25;++i)
{
for(j=1;j<=20;++j)
{
if(i==1||i==2)
cout<<"*";
else
{
if(j==1)
cout<<"**";
else
cout<<" ";
}
}
cout<<"\n\t\t\t";
}
for(i=1;i<=10;++i)
{
for(j=1;j<=20;++j)
{
if(i==1||i==2)
{ if(j==1||j==14||j==15||j==16)
cout<<"**";
  else
  cout<<" ";
}
else
{
if(i==9||i==10)
cout<<"*";
else
{  if(j==1||j==18)
  cout<<"**";
  else
  cout<<" ";
}
}
}
cout<<"\n\t\t\t";
}
break;


 case'H':

cout<<"\t\t\t";
for(i=1;i<=40;++i)
{
for(j=1;j<=21;++j)
{
if(i==20||i==21)
cout<<"*";
else
{
if(j==1||j==19)
cout<<"**";
else
cout<<" ";
}
}
cout<<"\n\t\t\t";
}
break;

return 0;
}

OUTPUT :