Followers

Showing posts with label CALCULATION. Show all posts
Showing posts with label CALCULATION. Show all posts

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

CHECKING A LIST OF INTEGERS FOR PALINDROME

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

long int rev=0, a[10];
int nmbr;

void revrse(int n)
{

  do
  {
    int temp=n%10;
    rev=(rev*10)+temp;
    n=n/10;
  }while(n!=0);
}

void cmpare(int n)
{
  cout<<"\n\t"<<rev;
  if(n==rev)
    cout<<"PALINDROME";
  else
    cout<<"NON-PALINDROME";
  cout<<"\n";
}

void main()
{
  clrscr();
  cout<<"enter the number of integers : ";
  cin>>nmbr;
  cout<<"Enter the integers : ";
  for(int i=0 ; i<nmbr ; i++)
    cin>>a[i];
  for( i=0 ; i<nmbr ; i++)
  {
    revrse(a[i]);
    cmpare(a[i]);
    rev=0;
  }

  getch();
}
.................................................................
OUTPUT :(click to enlarge the image)

Friday, January 6, 2012

SUM OF A RANGE

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

void main()
{
 int n, m, a=0, b=0;
 cout<<"Enter the starting number :";
 cin>>n;
 cout<<"Enter the last number :";
 cin>>m;
 a=n;
 int i=0;
 do
 {
  a=n+i;
  b=b+a;
  i++;
 }while(i<=m-n);
 cout<<"Sum of the range ="<<b;
 getch();
}
.................................................................
OUTPUT: (click to enlarge the image)

Friday, December 23, 2011

CALCULATING EXPONENT USING - math.h

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

void main()
{
 clrscr();
 int x, n;
 cout<<"Enter the base ";
 cin>>x;
 cout<<"Enter the power ";
 cin>>n;
 cout<<"The result of the given exponent is : "<<pow(x,n);
 getch();
}
.................................................................
OUTPUT:(click to enlarge the image)

Saturday, December 3, 2011

PRIME FACTORISATION

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

void main()
{
 clrscr();
 int n, x, m;
 cout<<"Enter any number : ";
 cin>>n;
 cout<<"Prime factors : \n";
 m=n;
 for(int i=2; i<=n/2;)
  {

   x=m%i;
   if(x==0)
    {
     cout<<i<<"\n";
     m=m/i;
    }
   else
    i=++i;
  }
 getch();
}
.................................................................
OUTPUT:(click on image to enlarge)

CHECK EVEN OR ODD NUMBER

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

void main()
{
 clrscr();
 int a;
 cout<<"Enter any number : ";
 cin>>a;
 (a%2==0)?cout<<"Even number":cout<<"Odd number";
 getch();
}
.................................................................
OUTPUT:(click on image to enlarge)

CHECK FOR PRIME NUMBER

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

void main()
{
 clrscr();
 int n, x;
 cout<<"Enter a number :";
 cin>>n;
 for(int i=2; i<=n/2; i++)
  {
   x=n%i;
   if(x==0)
    {
     cout<<"\nNon-prime number";
     i=n+1;
    }
  }
 if(x>0)
  cout<<"\nPrime number";
 getch();
}
.................................................................
OUTPUT:(click on image to enlarge)