HCF and LCM USING C
- Get link
- X
- Other Apps
//TESTED IN TERMINAL
//C program to find hcf and lcm: The code below finds highest common factor and least common multiple of two integers. HCF is also known as greatest common divisor(GCD) or greatest common factor(gcf).
#include<stdio.h>
void main()
{
int a,b,c,d,e;
printf("Enter 2 numbers:\n");
scanf("%d %d",&a,&b);
c=a;d=b;
while(a!=b)
{
if(a>b)
a=a-b;
else
b=b-a;
}
printf("hcf of %d and %d is %d\n",c,d,a);
{
e=((c*d)/a);
printf("lcm of %d and %d is %d\n",c,d,e);
}
}

- Get link
- X
- Other Apps
Popular posts from this blog
FIND NUMBER OF VOWELS IN A STRING
FIND NUMBER OF VOWELS IN A STRING c=raw_input("Enter A String:") b=c.lower() x=0 for letter in b: if letter in "aeiou": x+=1 print "Total Number Of Vowels = " + str(x) print "Number Of Vowels In Each" d,e,f,g,h=0,0,0,0,0 for letter in b: if letter in "a": d+=1 print "a=" +str(d) for letter in b: if letter in "e": e+=1 print "e=" +str(e) for letter in b: if letter in "i": f+=1 print "i=" +str(f) for letter in b: if letter in "o": g+=1 print "o=" +str(g) for letter in b: if letter in "u": h+=1 print "u=" +str(h) OUTPUT
TO FIND EVEN NUMBERS UP TO N
ENTERED NUMBER IS PRIME OR NOT
ENTERED NUMBER IS PRIME OR NOT n=int(input("enter a number:")) if n<0: print "enter a valid input" elif n<2: print "neither prime nor composite" else: for i in range(2,n/2): if(n%i)==0: print n,"is not a prime number" break else: print n,"is a prime number" OUTPUT --------------------------------------------------------------------------------------------------------------------------
Comments
Post a Comment