Problem Statement for LCM:
Enter Two digits by a user and get its LCM
Answer:
#include
#include
void main()
{
int x,y,i,j;
clrscr();
printf("Enter Two Digits");
scanf("d",&x,&y);
for(i=1;i<=x;i++)
{
for(j=1;j<=y;j++)
{
if(y*i==x*j)
{
printf("LCM is %d\n",y*i);
i=i+x;
}
}
}
getch();
}
OR
there will be another easy way to solve it...
Answer:
#include
#include
void main()
{
int x,y,i,;
clrscr();
printf("Enter Two Digits = ");
scanf("d",&x,&y);
for(i=1;i<=x*y;i++) {
if(i%x==0&&i%y==0)
{
printf(LCM is %d",i);
break;
}
}
getch();
}
Hey Friends here is the program of HCF and LCM with output:
Statement of C Program: Find The LCM and HCF of Two Numbers :
#include
void main()
{
int num1 , num2 , lcm , gcd , remainder , numerator , denominator ;
clrscr();
printf( "Enter two numbers\n");
scanf(" %d%d " , &num1 , &num2 );
if (num1 > num2)
{
numerator=num1;
denominator=num2;
}
else
{
numerator = num2 ;
denominator = num1 ;
}
remainder = num1 % num2;
while ( remainder != 0)
{
numerator = denominator;
denominator = remainder;
remainder = numerator % denominator;
}
gcd = denominator;
lcm = (num1 * num2 ) / gcd;
printf("GCD of %d and %d =%d\n" , num1, num2, gcd);
printf(" LCM of %d and %d= %d\n" , num1, num2, lcm);
getch();
}
Output:
Enter two numbers
5
15
GCD of 5 and 15 = 5
LCM of 5 and 15 = 15
01#include <iostream>
02using namespace std;
03
04
05int gcf(int a, int b ) {
06 int rem = a % b;
07 while (rem != 0){
08 rem = b % rem;
09 rem--;
10 return b;
11 }
12
13}
14
15
16int main () {
17
18 int x, y;
19 cout << "Enter two integers: ";
20 cin >> x >> y;
21
22 cout << "The greatest common factor of " << x << " and " << y
23 << " is " << gcf(x, y) << endl;
24
25 return 0;
26}
A = 5do{statement;A = A + 1;} while (A < 10)
Using while loop, write a program which calculates the product of digits from 1 to 5 and also show these no's vertically.
class Abc { public static void main(String[] args) { System.out.println("Hello World!"); } }
A program can be looped in Python by wrapping the entire program in a for or while loop. If you wish to loop the program a finite amount of times, it can be done like so (x = the amount of times you want it to loop, this can be a number or variable storing a number): for i in range(0,x): [code] If you wish to loop the program infinitely, you can use a simple while loop: while True: [code]
by this program you can find the factorial: #include<iostream> using namespace std; main() { int n,x,f=1; cin>> n; x=0; while(x<n) { x++; f= f*x; } cout<<"factorial is"<<f<<"\n"; system("pause"); return 0; }
Not used
//program to find the factorial value f any number using while loop #include<stdio.h> void main() { int i,n,fact=1; printf("Enter the number\n"); scanf("%d",&n); i=n; while (i>=1) { fact=fact*i; i--; } printf("The factorial value=%d",fact); } the above is a program for calculating tha factorial value of any number which is entered by the user
A = 5do{statement;A = A + 1;} while (A < 10)
Using while loop, write a program which calculates the product of digits from 1 to 5 and also show these no's vertically.
int i=0; while (i++<n) { /*...*/ }
class Abc { public static void main(String[] args) { System.out.println("Hello World!"); } }
A program can be looped in Python by wrapping the entire program in a for or while loop. If you wish to loop the program a finite amount of times, it can be done like so (x = the amount of times you want it to loop, this can be a number or variable storing a number): for i in range(0,x): [code] If you wish to loop the program infinitely, you can use a simple while loop: while True: [code]
#define int main (void){/*Algorithm*/1. First Initialize the number that is Random no2. Using while loop if the person got it, then the loop stop if not the loop continues.}return(0);
How do you write a program with do while loop so that the output is 123456 =720
by this program you can find the factorial: #include<iostream> using namespace std; main() { int n,x,f=1; cin>> n; x=0; while(x<n) { x++; f= f*x; } cout<<"factorial is"<<f<<"\n"; system("pause"); return 0; }
With loops, your program is slower.
Wr