Respuesta :
Answer:
Program is written in C++
#include<iostream>
using namespace std;
int main()
{
//1. Prime Number
int num;
cout<<"Input Number: ";
cin>>num;
int chk = 0;
for(int i =2; i <num;i++)
{
if(num%i==0)
{
chk = 1;
break;
}
}
if(chk == 0)
{
cout<<num<<" is prime"<<endl;
}
else
{
cout<<num<<" is not prime"<<endl;
}
//2. Greatest Common Factor
int num1, num2, x, y, temp, gcf;
cout<<"Enter two numbers: ";
cin>>num1;
cin>>num2;
x = num1;
y = num2;
while (y != 0) {
temp = y;
y = x % y;
x = temp;
}
gcf = x;
cout<<"Greatest Common Factor: "<<gcf<<endl;
// 3. LCM
cout<<"Enter two numbers: ";
cin>>num1;
cin>>num2;
x = num1;
y = num2;
while (y != 0) {
temp = y;
y = x % y;
x = temp;
}
gcf = x;
int lcm =(num1 * num2)/gcf;
cout<<"Least Common Multiple: "<<lcm<<endl;
return 0;
}
Explanation:
I've added the full source code as an attachment where I make use of comments to explain some lines