blob: 14e1718904f83aed626993eef3d59c6df7105c91 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
//Chapter 05: Induction and Recursion
clc;
clear;
function res=greatestcommondivisior(a,b)
if a==0 then
res=b
else
res=greatestcommondivisior(modulo(b,a),a)
end
return res
endfunction
num1=input("Enter the first number:")
num2=input("Enter the second number:")
res_gcd=greatestcommondivisior(num1,num2)
mprintf("The gcd of %d , %d is %d",num1,num2,res_gcd)
//By Using the inbuilt function,that is provided by Scilab
p=[num1,num2]
res=gcd(p)
mprintf("\nThe gcd of %d , %d is %d",num1,num2,res)
|