Hello I am trying to alter the sine cosine and tangent fucntion Math.sin Math.co
ID: 3570996 • Letter: H
Question
Hello I am trying to alter the sine cosine and tangent fucntion Math.sin Math.cos Math.tan so it can accept degrees How you alter them so it can accept a degree see my main fucnction I wrote the functions but I do not know how to alter the Math fucntions
var sin = function() {
if (arguments[1] == "d") {
arguments[0] = arguments[0] * Math.PI / 180;
}
return (Math.sin(arguments[0]));
};
var cos = function() {
if (arguments[1] == "d") {
arguments[0] = arguments[0] * Math.PI / 180;
}
return (Math.cos(arguments[0]));
};
var tan = function() {
if (arguments[1] == "d") {
arguments[0] = arguments[0] * Math.PI / 180;
}
return (Math.tan(arguments[0]));
};
Math.sin = function(angle, degree) { //it fails
sin(angle, degree);
};
(function() {
var angle;
while (angle = parseFloat(readline())) {
print(Math.sin(angle, "d").toPrecision(5)); // degrees
print(Math.sin(angle).toPrecision(5)); // radians
print(Math.cos(angle, "d").toPrecision(5));
print(Math.cos(angle).toPrecision(5));
print(Math.tan(angle, "d").toPrecision(5));
print(Math.tan(angle).toPrecision(5));
}
})();
Explanation / Answer
Multiply the result by 180/Math.PI to convert from radians to degrees.
You could also define your own functions:
and so on.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.