1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
OLga [1]
3 years ago
12

Implementations in c++ programming when finding lcm and gcd in c++​

Computers and Technology
1 answer:
vazorg [7]3 years ago
7 0

Answer:

#include<iostream>

using namespace std;

int lcm(int m, int n) {

  int a;

  a = (m > n) ? m: n;

  while (true) {

     if (a % m == 0 && a % n == 0)

        return a;

        ++a;

  }

}

int gcd(int m, int n) {

  int r = 0, a, b;

  a = (m > n) ? m : n;

  b = (m < n) ? m : n;

  r = b;

  while (a % b != 0) {

     r = a % b;

     a = b;

     b = r;

  }

  return r;

}

int main(int argc, char **argv) {

  cout << "Enter the two numbers: ";

  int m, n;

  cin >> m >> n;

  cout << "The LCM of two numbers is: " << lcm(m, n) << endl;

  cout << "The GCD of two numbers is: " << gcd(m, n) << endl;  

  return 0;

}

Explanation:

You might be interested in
This is not what I asked for​
jolli1 [7]
?? What does that mean? What is the question
3 0
2 years ago
Consider the following code example:
yKpoI14uk [10]

Answer:

The number of invoices for each vendor that have a larger balance due than the average balance due for all invoices.

Explanation:

This part of the code below

WHERE InvoiceTotal - PaymentTotal - CreditTotal >

(SELECT AVG (InvoiceTotal - PaymentTotal- CreditTotal)

FROM Invoices)

gives the condition to pick the invoices with balance that are greater than the average balance for all invoice.

This part of the code below

GROUP BY VendorName

ORDER BY BalanceDue DESC;

then enables the program to group the result of the above condition by VendorName and sort the resulting rows in the order of BalanceDue. You will therefore, obtain for each row in the NumberOfInvoices column, the number of invoices for each vendor that have a larger balance due than the average balance due for all invoices.

7 0
3 years ago
Mintzberg's classification of organizational structure categorizes the knowledge-based organization where goods and services dep
sineoko [7]

Answer:

The correct answer to the following question will be Option 3 (Professional bureaucracy).

Explanation:

  • Professional bureaucracy is evidence that uncentralized organizations can be administrative. Their organizational function is reliable, culminating in "preconceived or repetitive actions, in essence, uniform."It's also very complicated, and so the operators who are doing it should be regulated.
  • Mintzberg's organizational framework categorization classifies the information-based organization where services and goods depend as a highly qualified bureaucracy on both the knowledge and expertise of experts.

The other alternatives are not related to the structure of the Mintzberg. So choice 3 is the correct answer.

8 0
3 years ago
When you connect several home devices using a wireless router, what network topology are you using? A. bus B. mesh C. star D. ri
bonufazy [111]

Answer:

Star Topology

Explanation:

Because the definition of Star Topoplogy is: In star topology each device in the network is connected to a central device called hub. Unlike Mesh topology, star topology doesn’t allow direct communication between devices, a device must have to communicate through hub. If one device wants to send data to other device, it has to first send the data to hub and then the hub transmit that data to the designated device.

3 0
2 years ago
write a python function that takes the largest and smallest numbers in a list, and swap them (without using min() or max() )
Akimi4 [234]

Answer:

def SwapMinMax ( myList ):

   myList.sort()

   myList[0], myList[len(myList)-1] = myList[len(myList)-1], myList[0]

   return myList

   

Explanation:

By sorting the list, you ensure the smallest element will be in the initial position in the list and the largest element will be in the final position of the list.

Using the len method on the list, we can get the length of the list, and we need to subtract 1 to get the maximum element index of the list.  Then we simply swap index 0 and the maximum index of the list.

Finally, we return the new sorted list that has swapped the positions of the lowest and highest element values.

Cheers.

8 0
2 years ago
Other questions:
  • Who developed one of the first mathematical models of a multilevel security computer system?
    15·1 answer
  • if the president goes for vice president after his 2 term and the present president dies is the old president the president agai
    8·2 answers
  • I'll pay 50 dollars to anyone who can do this leave your snap after answering doing it and ill cash app it
    13·1 answer
  • Complete the paragraph to explain how Angelina can notify readers that her report is just a draft.
    6·1 answer
  • Given the following function definition, what modifications need to be made to the search function so that it finds all occurren
    7·1 answer
  • The term generally used to describe storage systems that function at high speeds is:
    12·1 answer
  • What is the definition of the word uproot?
    15·1 answer
  • What is the difference, if any, between a project manager and a producer on a digital media production team? A project manager o
    10·1 answer
  • PLEASE HELP How have phones made us spoiled? How have phones made us unhappy?
    10·1 answer
  • Rohan is creating a presentation with at least 50 slides. He wants the slides to use a consistent layout and formatting. Which o
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!