Followers

Thursday, March 15, 2012

HCF


#include<iostream.h>
#include<conio.h>
int n1, n2, a, hcf;
void main()
{
  cout<<"Enter two numbers : ";
  cin>>n1>>n2;
  if(n1<n2)
    a=n1;
  else
    a=n2;
  for(int i=a; i>=1 ; i--)
  {
    if(n1%i==0 && n2%i==0)
    {
      hcf=i;
      break;
    }
  }
  cout<<"\nHCF = "<<hcf;
  getch();
}
.................................................................
OUTPUT :(click to enlarge the image)

LCM

#include<iostream.h>
#include<conio.h>
int n1, n2, lcm,a;
void main()
{
  cout<<"Enter two integers : ";
  cin>>n1>>n2;
  cout<<"\nLCM = ";
  if(n1>n2)
    a=n2;
  else
    a=n1;
  for(int i=a; i<=((n1)*(n2)); i++)
  {
    if(i%n1==0 && i%n2==0)
    {
      lcm=i;
      break;
    }
  }
  cout<<"\n"<<lcm;
  getch();
}
.................................................................
OUTPUT :(click to enlarge the image)

Wednesday, March 14, 2012

INVERTED TRIANGLE OF (*)

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

void main()
{
 clrscr();
 int n;
 cout<<"enter the number of lines :";
 cin>>n;
 for(int i=n; i>=1 ; i--)
 {
   for(int j=i ; j>=1 ; j--)
     cout<<"*";
   cout<<"\n";
 }
 getch();
}
.................................................................
OUTPUT :(click to enlarge the image)

LATERALLY INVERTED TRIANGLE OF ALPHABETS

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

void main()
{
 int n;
 cout<<"enter the number of lines :";
 cin>>n;
 for(int i=1 ; i<=n ; i++)
 {
   for(int j=1 ; j<=n-i ; j++)
     cout<<" ";
   for(int k=1 ; k<=i ; k++)
     cout<<char(64+k);
   cout<<"\n";
 }
 getch();
}
.................................................................
OUTPUT :(click to enlarge the image)

LATERALLY INVERTED TRIANGLE OF ALPHABETS

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

void main()
{
 int n;
 cout<<"enter the number of lines :";
 cin>>n;
 for(int i=1 ; i<=n ; i++)
 {
   for(int j=1 ; j<=n-i ; j++)
     cout<<" ";
   for(int k=1 ; k<=i ; k++)
     cout<<char(64+k);
   cout<<"\n";
 }
 getch();
}
.................................................................
OUTPUT :(click to enlarge the image)

TRIANGLE OF NUMBERS

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

void main()
{
 clrscr();
 int n;
 cout<<"enter the number of lines :";
 cin>>n;
 for(int i=1 ; i<=n ; i++)
 {
   for(int j=1; j<=i ; j++)
     cout<<(0+j);
   cout<<"\n";
 }
 getch();
}
.................................................................
OUTPUT :(click to enlarge the image)

DIAMOND OF (*)

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

void main()
{
 clrscr();
 int n, a, b;
 cout<<"enter the number of lines : ";
 cin>>n;
 a=((n/2)+1);
 b=n-a;
 for(int i=1 ; i<=a ; i++)
 {
   for(int j=1 ; j<=a-i ; j++)
     cout<<" ";

   for(int k=1 ; k<=i ; k++)
     cout<<"*";

   for(int l=2 ; l<=i ; l++)
     cout<<"*";
   cout<<"\n";
 }

 int c=b+1;
// int d=b-1;

 for(int p=1; p<=b ; p++)
 {
  for(int q=1 ; q<=p ; q++)
    cout<<" ";
  for(int s=1 ; s<=c-p ; s++)
    cout<<"*";
  for(int r=1 ; r<=b-p ; r++)
    cout<<"*";
  cout<<"\n";
 }
 getch();
}
.................................................................
OUTPUT :(click to enlarge the image)