Good morning, could you help me to perform the following problem using  scilab? Using basic commands like while. Thank you very much in advance. Write a program that can compute the greatest common divisor of a pair of positive integers a and b. As a reminder, the greatest common divisor is the largest integer that divides each of the numbers with no remainder. For example: The greatest common divisor of 2 and 12 is 2. The greatest common divisor of 17 and 12 is 1 The greatest common divisor of 9 and 12 is 3. A tip is to start testing with a number equal to the smaller of the two numbers entered by the user and iteratively reduce this test value by 1 until you reach the case where this value can divide both a and b without leaving a remainder or simply finish if this test value reaches 1.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question
100%

Good morning, could you help me to perform the following problem using  scilab? Using basic commands like while.
Thank you very much in advance.
Write a program that can compute the greatest common divisor of a pair of positive integers a and b. As a reminder, the greatest common divisor is the largest integer that divides each of the numbers with no remainder. For example:
The greatest common divisor of 2 and 12 is 2.
The greatest common divisor of 17 and 12 is 1
The greatest common divisor of 9 and 12 is 3.
A tip is to start testing with a number equal to the smaller of the two numbers entered by the user and iteratively reduce this test value by 1 until you reach the case where this value can divide both a and b without leaving a remainder or simply finish if this test value reaches 1.

 

 

Expert Solution
Step 1

For general programming language as python: 

the logic for code is:

def gcd(x, y):
   gcd = 1   
   if x % y == 0:
       return y   
   for k in range(int(y / 2), 0, -1):
       if x % k == 0 and y % k == 0:
           gcd = k
           break 
   return gcd
 
 
For Scilab we have functions as:
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Operators
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education