Q2.Program to find gcd of a number using recursion.m=6 n=4 while(n>0): r=n q=m%n m=r n=q print(m) >>> ==================== RESTART: C:/Users/Dell/Desktop/aq.py ==================== 2
Q3.Program to print pyramid.def gcd(m,n): if(n==0): return(m) else: return(gcd(n,m%n)) print(gcd(4,12)) >>> ==================== RESTART: C:/Users/Dell/Desktop/aq.py ==================== 4
Q4.Program to print number and number square from 0 to 9.for i in range(5): for j in range(0,i+1): print("*", end=" ") print("\r") Output ==================== RESTART: C:/Users/Dell/Desktop/we.py ==================== * * * * * * * * * * * * * * *
Q5 Program to find area of circle using function.def square(a): return(a*a) for i in range(10): print(i,square(i)) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/we.py ==================== 0 0 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81
def areacircle(pi,r): re=pi*r*r return(re) r=int(input("enter radius of circle")) print(areacircle(3.14,r)) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/we.py ==================== enter radius of circle2 12.56
0 Comments