Tuesday, 14 January 2020

Write a algorithm and python program to implement( import math- sqrt, ceil, floor, pow, fabs, sin, cos, tan )

# a) sqrt programming

import math
x=int(input(" Enter the x value"))
y=math.sqrt(x)
print("The square root of x value is=",y)

output:
 Enter the x value 64
The square root of x value is= 8.0

# b) ceil programming (Least integer function)

import math
x=eval(input(" Enter the x value"))
y=math.ceil(x)
print("The Least integer is=",y)

output
 Enter the x value 1.03
The Least integer is= 2

output
 Enter the x value -1.03
The Least integer is= -1

# c) floor programming ( Greatest integer function)

import math
x=eval(input(" Enter the x value"))
y=math.floor(x)
print("The Greatest integer is=",y)

output
 Enter the x value 1.03
The Greatest integer is= 1

 output
 Enter the x value -1.03
The Greatest integer is= -2

# d) pow programe
import math
a=int(input(" Enter the a value"))
b=int(input(" Enter the b value"))
y=math.pow(a,b)
print("a to the power b is=",y)

output
 Enter the a value 3
 Enter the b value 4
a to the power b is= 81.0


# e) fabs programming (Modulus function)

import math
a=eval(input(" Enter the a value"))
y=math.fabs(a)
print("Modulus of a is=",y)

output
Enter the a value -6.34
Modulus of a is= 6.34

# f) sin(x) programming

import math
x=eval(input(" Enter the degree value"))
r=math.radians(x)                                  # it converts degrees to radians
y=math.sin(r)                                     
print("sin(x) is =",y)

output
Enter the degree value 30
sin(x) is = 0.49999999999999994

Enter the degree value 0
sin(x) is = 0.0

Enter the degree value  90
sin(x) is = 1.0

# f) cos(x) programming

import math
x=eval(input(" Enter the degree value: "))
r=math.radians(x)                           # it converts degrees to radians
y=math.cos(r)                                     
print("cos(x) is = ",y)

output
Enter the degree value 0
cos(x) is = 1.0

Enter the degree value: 60
cos(x) is =  0.5000000000000001

# f) tan(x) programming


No comments:

Post a Comment