Comments (8)
from c.
I want to work on this issue.
from c.
@Sooraj2002 sure
from c.
//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.
//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.
//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.
/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.
You can try this out.
from c.
Related Issues (16)
- Type casting the result of malloc.
- .. HOT 3
- Sorting
- Hi, dude.
- C programming HOT 9
- Can there (or can we create a) be a similar data structures implementation in C++ (using OOP)?
- Pattern HOT 1
- File structures
- C program of implementation of array HOT 1
- Can a game library be created (or can we create a game library) where sample games are build using the data structures here? HOT 1
- help in C language .. HOT 5
- help me on the following c code HOT 3
- login page HOT 4
- . HOT 1
- Memory allocation HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from c.