Programming Examples 1
Programming Examples 1
be#aef →
defining fee a neotwo
god -7 name
of function
G#
.
1. input of
aio → fire function .
6% a → Remainder
def gcd(a, b):
if a == 0 : when 6 is divided
return b
by a .
return gcd(b%a, a)
25,35
25335 ( I 1) 25
§
-25 2÷
Remainder → To
5) so ¢
÷
So ,
GCD = 5
we
recursion
similarly
here we are
using
to find GCD .
number
dividing larger
the
Each
step we are
the
with the smaller number,
collecting
remainder
remainder and passing the
smaller number
to next step for
and the
division .
return
when remainder = 0
,
we simply
the GCD
of last step as
.
the divisor
'
(25,35) Remainder
-10
GCD
0
(5,103 Remainder =
GCD
Doesn't check
GCD (0,5) for remainder
⑤
a.)
N=len(A)
def alpha(A):
÷÷¥÷÷÷
For an
element
Ciii ) We are
swapping
it with
(ji )
so ,
in
place Transpose of . a
matrix
i=É .
I = 1 to N [1/213]
i=
[ ] for
'
N
j=i -11 to 2,3
[ a. 6
,
c ;D]
odd_sum = 0
even_sum = 0
Test -
list → list
of integers
a- a -16
test -
list [35,24/143]
④
test list :
a -1=6 for sub in -
in Straub) :
for ele
3%2=-0
'
3 ele -53
/ '
566--35-5
Eszu
ele -55
'
2
'
'
ele =
143 -
'
'
ele 4
f
" -_
'
ele il
3 '
ele → y
'
ele =-3
1,213141T
4) intf.no ,
whether
# Run loop from 0 to len/2 Checking
for i in range(0, len(str)//2): Str is
palindrome
- if str[i] != str[len(str)-i-1]: or not .
return False
-
→ Str >
string
-
- -
else
:retvrn Tries her Gtr) /12--2
0,1
4. return True
ÑADAm
☒ (0/2)
MOM DOOD
0¥ >a ← ( 0,2)
I :O stop] != Str [5-0-1] a-
Staci g✓
M
M
B0TA⑥µ
IT
stray ! = Str / 5-1-1] = Stats] t☐☒p☒B
A
A
012
31/2=1
BAT lenfstr) =3
G. 1)
staff ! -_
stay -
oifstrt) i=o⑧
B F- range
from 1 to N:
0 I
>
2
,
3,4 I 5
, ,
' '
Mother
[ 9,6I > id
2
]
3
012345
0
range [ 0,447
psaHrar.ge/ton;0-4-#I
?
: