Thursday, 8 December 2016

Program to find LCM of 2 nos.

#include<conio.h>
#include<iostream.h>
void main()
{ clrscr();
  int a,b,c,d,e;
  cout<<"Enter 2 nos. ";
  cin>>a>>b;
  for (int i=a;i>=1;i--)
      { c=a*i;
for (int j=b;j>=1;j--)
   { d=b*j;
     if (c==d)
 e=c;
   }
      }
  cout<<"LCM is "<<e;
  getch();
}

Program to find HCF of 2 nos. usin' Function

#include<conio.h>
#include<iostream.h>
int HCF_of(int x,int y);
void main()
{ clrscr();
  int x,y,z;
  cout<<"Enter 2 nos. ";
  cin>>x>>y;
  z=HCF_of(x,y);
  cout<<"HCF is "<<z;
  getch();
}
int HCF_of(int x,int y)
{ int a,b,c;
  a=x>y?x:y;
  b=x<y?x:y;
  for (int i=1;i<=a;i++)
      { if (a%i==0)
  { if (b%i==0)
c=i;
  }
      }
  return(c);
}

Program to find HCF of 2 nos.

#include<conio.h>
#include<iostream.h>
void main()
{ clrscr();
  int x,y,z,a,b,c;
  cout<<"Enter any 2 nos. ";
  cin>>x>>y;
  z=x<y?x:y;
  a=x>y?x:y;
  for(int i=1;i<=z;i++)
     { b=z%i;
       if (b==0)
 { if (a%i==0)
      { c=i;
      }
 }
     }
  cout<<"HCF is "<<c;
  getch();
}

Basic Implementation of Array as a Pointer

#include<iostream.h> #include<conio.h> void main() { clrscr();   int arr[5];   cout<<"Enter 5 nos. ";   f...