Giter Club home page Giter Club logo

Comments (8)

Abircr7 avatar Abircr7 commented on August 23, 2024

from c.

Sooraj2002 avatar Sooraj2002 commented on August 23, 2024

I want to work on this issue.

from c.

devmalik7 avatar devmalik7 commented on August 23, 2024

@Sooraj2002 sure

from c.

Sooraj2002 avatar Sooraj2002 commented on August 23, 2024

//PROGRAM TO FIND HCF OF TWO NO'S
#include<stdio.h> #include<conio.h> int main() { int num1, num2, mp; printf("Enter two Numbers: "); scanf("%d %d", &num1, &num2); if(num1>num2) mp=num1; else mp=num2; while(1) { if((num1%mp==0) && (num2%mp==0)) break; else mp--; } printf("\nHCF(%d,%d) = %d", num1, num2, mp); getch(); return 0; }

from c.

heyyayesh avatar heyyayesh commented on August 23, 2024

//Program to find the LCM of two numbers

#include <stdio.h>

int main(){
int n1, n2, x;
printf("Enter two numbers: \n");
scanf("%d %d", &n1, &n2);

if(n1==n2){
    printf("LCM is %d.\n", n1);
    return 0;
}

x = (n1>n2) ? n1 : n2;

for(int i = 1; i <= n1*n2; i++, x++){
    if(x % n1 == 0 && x % n2 == 0){
        printf("LCM is %d.\n", x);
        break;
    }
}

return 0;

}

from c.

R-eng-2104 avatar R-eng-2104 commented on August 23, 2024

//Program to find the LCM of two numbers

#include <stdio.h>

int main(){
int n1, n2, x;
printf("Enter two numbers: \n");
scanf("%d %d", &n1, &n2);

if(n1==n2){
    printf("LCM is %d.\n", n1);
    return 0;
}

else if x = (n1>n2) ? n1 : n2;/should be i think/

for(int i = 1; i <= n1*n2; i++, x++){
    if(x % n1 == 0 && x % n2 == 0){
        printf("LCM is %d.\n", x);
        break;
    }
}

return 0;

}

from c.

Shree-Gillorkar avatar Shree-Gillorkar commented on August 23, 2024

/Write a program to find the HCF and LCM of the given number without using the multiplication and division./

#include<bits/stdc++.h>
using namespace std;
int multiply(int firstnum, int secondnum){

// If second number is zero then the product is zero.

if(secondnum == 0){
    return 0;
} else {

   // Add first num, until second num is equal to zero.
   return (firstnum + multiply(firstnum, secondnum-1));
}

}

int divide(int x, int y){
// handle divisibility by 0
if (y == 0)
{
printf("Error!! Divisible by 0");
exit(1);
}

// store sign of the result
int sign = 1;
if (x * y < 0) {
    sign = -1;
}

// convert both dividend and divisor to positive
x = abs(x), y = abs(y);

// initialize quotient by 0
int quotient = 0;

// loop till dividend `x` becomes less than divisor `y`
while (x >= y)
{
    x = x - y;      // perform a reduction on the dividend
    quotient++;     // increase quotient by 1
}

return sign * quotient;

}

// Driver code
#include <stdio.h>
int main() {
int a, b, x, y, t, hcf, lcm;

printf("Enter two integers\n");
scanf("%d%d", &x, &y);

a = x;
b = y;

while (b != 0) {
t = b;
b = a % b;
a = t;
}

hcf = a;
lcm = divide(multiply(x,y),hcf);

printf("Highest Common Factor of %d and %d = %d\n", x, y, hcf);
printf("Least common multiple of %d and %d = %d\n", x, y, lcm);

return 0;
}

from c.

Shree-Gillorkar avatar Shree-Gillorkar commented on August 23, 2024

You can try this out.

from c.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.