C Program to calculate LCM and HCF/GCD of two numbers



#include 

int LCM (int ,int);

int HCF (int ,int);

int main(){
 int a,b,L,H;
 printf("enter two numbers\n");
 scanf ("%d%d",&a,&b);
 L=LCM(a,b);
 H=HCF(a,b);
 printf("LCM is %d and HCF is %d",L,H);
 return 0;
}

int LCM (int x, int y){
 int L;
 for (L=1;L<=x*y;L++)
  if (L%x==0 && L%y==0)
   break;
  return (L);
}

int HCF (int x, int y){
 int H;
 for (H=(x=1;H--)
  if (x%H==0 && y%H==0)
   break;
  return (H);
}

Java program to find factorial of a number without using Multiplication Operator (*) or Asterisk



import java.util.Scanner;
public class FactorialWOAsterisk {
public static void main(String[] args) {

    System.out.println("Enter a  number of which you want to find factorial:");

    Scanner take = new Scanner(System.in);

    int num = take.nextInt();
    int factorial = 1;
    for(int i = 1; i <= num; ++i)
    {
              // factorial = factorial * i;
              factorial = FindMultiplicationWOAsterisk(factorial,i);
    }
    System.out.println("Factorial of " + num + " is "+ factorial);
}

public static int FindMultiplicationWOAsterisk(int x, int y){
  int product = 0;
  while(y != 0)
     {
       product += x;
        y--;
     }
  return (product);
 }
}