Skip to main content
added 28 characters in body; edited body
Source Link
James
  • 451
  • 3
  • 4

JavaScript - 133 chars

y=(z=prompt)().split(" "),s=[0,0],l=1;for(i=0;i<y[1]*2;i++){s[i%2]+=i%4>1?-1*l:l;l*=y[0]/(i+1)}z(s[1].toFixed(86));z(s[0].toFixed(86));

Ungolfed

var xy = prompt();
var n = prompt.split(" ");

var out = [0,0]; // out[1] is sin(x), out[0] is cos(x)
var l = 1; // keep track of last term in series
for (var i=0; i < ny[1] * 2; i++) {
    out[i % 2] += (i % 4 > 1) ? -1 * l : l;
    l *= xy[0] / (i + 1);
}

alertprompt(out[1].toFixed(86));
alertprompt(out[0].toFixed(86));

JavaScript - 133 chars

y=(z=prompt)().split(" "),s=[0,0],l=1;for(i=0;i<y[1]*2;i++){s[i%2]+=i%4>1?-1*l:l;l*=y[0]/(i+1)}z(s[1].toFixed(8));z(s[0].toFixed(8));

Ungolfed

var x = prompt();
var n = prompt();

var out = [0,0]; // out[1] is sin(x), out[0] is cos(x)
var l = 1; // keep track of last term in series
for (var i=0; i < n * 2; i++) {
    out[i % 2] += (i % 4 > 1) ? -1 * l : l;
    l *= x / (i + 1);
}

alert(out[1].toFixed(8));
alert(out[0].toFixed(8));

JavaScript - 133 chars

y=(z=prompt)().split(" "),s=[0,0],l=1;for(i=0;i<y[1]*2;i++){s[i%2]+=i%4>1?-1*l:l;l*=y[0]/(i+1)}z(s[1].toFixed(6));z(s[0].toFixed(6));

Ungolfed

var y = prompt().split(" ");

var out = [0,0]; // out[1] is sin(x), out[0] is cos(x)
var l = 1; // keep track of last term in series
for (var i=0; i < y[1] * 2; i++) {
    out[i % 2] += (i % 4 > 1) ? -1 * l : l;
    l *= y[0] / (i + 1);
}

prompt(out[1].toFixed(6));
prompt(out[0].toFixed(6));
Added syntax highlighting
Source Link
ProgramFOX
  • 8.3k
  • 7
  • 45
  • 70
 

JavaScript - 133 chars

y=(z=prompt)().split(" "),s=[0,0],l=1;for(i=0;i<y[1]*2;i++){s[i%2]+=i%4>1?-1*l:l;l*=y[0]/(i+1)}z(s[1].toFixed(8));z(s[0].toFixed(8));
y=(z=prompt)().split(" "),s=[0,0],l=1;for(i=0;i<y[1]*2;i++){s[i%2]+=i%4>1?-1*l:l;l*=y[0]/(i+1)}z(s[1].toFixed(8));z(s[0].toFixed(8));

Ungolfed

var x = prompt();
var n = prompt();

var out = [0,0]; // out[1] is sin(x), out[0] is cos(x)
var l = 1; // keep track of last term in series
for (var i=0; i < n * 2; i++) {
    out[i % 2] += (i % 4 > 1) ? -1 * l : l;
    l *= x / (i + 1);
}

alert(out[1].toFixed(8));
alert(out[0].toFixed(8));
var x = prompt();
var n = prompt();

var out = [0,0]; // out[1] is sin(x), out[0] is cos(x)
var l = 1; // keep track of last term in series
for (var i=0; i < n * 2; i++) {
    out[i % 2] += (i % 4 > 1) ? -1 * l : l;
    l *= x / (i + 1);
}

alert(out[1].toFixed(8));
alert(out[0].toFixed(8));

JavaScript - 133 chars

y=(z=prompt)().split(" "),s=[0,0],l=1;for(i=0;i<y[1]*2;i++){s[i%2]+=i%4>1?-1*l:l;l*=y[0]/(i+1)}z(s[1].toFixed(8));z(s[0].toFixed(8));

Ungolfed

var x = prompt();
var n = prompt();

var out = [0,0]; // out[1] is sin(x), out[0] is cos(x)
var l = 1; // keep track of last term in series
for (var i=0; i < n * 2; i++) {
    out[i % 2] += (i % 4 > 1) ? -1 * l : l;
    l *= x / (i + 1);
}

alert(out[1].toFixed(8));
alert(out[0].toFixed(8));
 

JavaScript - 133 chars

y=(z=prompt)().split(" "),s=[0,0],l=1;for(i=0;i<y[1]*2;i++){s[i%2]+=i%4>1?-1*l:l;l*=y[0]/(i+1)}z(s[1].toFixed(8));z(s[0].toFixed(8));

Ungolfed

var x = prompt();
var n = prompt();

var out = [0,0]; // out[1] is sin(x), out[0] is cos(x)
var l = 1; // keep track of last term in series
for (var i=0; i < n * 2; i++) {
    out[i % 2] += (i % 4 > 1) ? -1 * l : l;
    l *= x / (i + 1);
}

alert(out[1].toFixed(8));
alert(out[0].toFixed(8));
Source Link
James
  • 451
  • 3
  • 4

JavaScript - 133 chars

y=(z=prompt)().split(" "),s=[0,0],l=1;for(i=0;i<y[1]*2;i++){s[i%2]+=i%4>1?-1*l:l;l*=y[0]/(i+1)}z(s[1].toFixed(8));z(s[0].toFixed(8));

Ungolfed

var x = prompt();
var n = prompt();

var out = [0,0]; // out[1] is sin(x), out[0] is cos(x)
var l = 1; // keep track of last term in series
for (var i=0; i < n * 2; i++) {
    out[i % 2] += (i % 4 > 1) ? -1 * l : l;
    l *= x / (i + 1);
}

alert(out[1].toFixed(8));
alert(out[0].toFixed(8));