[ create a new paste ] login | about

Link: http://codepad.org/dWQbZ9PV    [ raw code | output | fork | 3 comments ]

C, pasted on Sep 14:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define eps 1e-4 // Sai số
int main()
{
	float S, T, x, LuyThua, GiaiThua;
	int i, Dau = -1;

	printf("\nNhap x(radian): ");
	scanf("%f", &x);

	GiaiThua = 1;
	S = T = LuyThua = x;
	for(i = 3; T > eps; i += 2, Dau = -Dau)
	{
		T = (LuyThua *= x * x) / (GiaiThua *= i * (i - 1));
		S += Dau * T;
	}
	printf("\nCong thuc Taylor: sin (%.2f) = %.4f", x, S);
	printf("\nSin () cua math.h: sin(%.2f) = %.4f", x, sin(x));


	getch();
	return 0;
}


Output:
1
Line 17: error: conio.h: No such file or directory


Create a new paste based on this one


Comments:
posted by test22 on Nov 4

reply
posted by test22 on Nov 4
<h1>Adsad</h1>
reply
posted by lehoangan01 on Feb 1
#include <iostream>
#include <math.h>
using namespace std;

int main() {
int i, j, n, fact, sign = -1;
float x, p, sum = 0;

printf("Enter the value of x: ");
scanf("%f", &x);
printf("Enter the value of n: ");
scanf("%d", &n);

for (i = 1; i <= n; i += 2){
p = 1;
fact = 1;
for ( j = 1; j <= i; j++){
p = p * x;
fact = fact * j;
}
sign = -1 * sign;
sum += sign * p / fact;
}

printf("sin %0.2f = %f", x, sum);
return 0;
}

reply