[ create a new paste ] login | about

Link: http://codepad.org/m096ZUpT    [ raw code | output | fork | 4 comments ]

C, pasted on Aug 24:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
	int i, n;
	float x, S, T;
	long M, N;
	printf("\nNhap x: ");
	scanf("%f", &x);
	do
	{
	printf("\nNhap n(n >= 1) : ");
	scanf("%d", &n);
	  if(n < 1)
	  {
		  printf("\n N phai >= 1. Xin nhap lai !");
	  }

	}while(n < 1);

	S = 1;
	N = 1;
	i = 1;

	while(i <= n)
	{
		T = pow(x, (2 * i + 1));
		M = i * 2 + 1;
		N = N * M * (M - 1);
		S = S + x + T/N;
		i++;
	}
	printf("\nTong la %f", S);
	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 kendypham on Nov 9
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int i, n;
float x, S;
long N,a;
printf("\nNhap x: ");
scanf("%f", &x);
do
{
printf("\nNhap n(n >= 0) : ");
scanf("%d", &n);
if(n < 0)
{
printf("\n N phai >= 0. Xin nhap lai !");
}

}while(n < 0);

S = 1;
N = 1;

for(i=0;i<=n;i++)
{
a=N+i;
S = S + pow(x,2*i+1)/(a);
}
printf("\nTong la %f", S);
getch();
return 0;
}

reply
posted by bangtran on Jan 22
sai đoạn S = 1 vs S = S + x + T/N
sửa lại:

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int i, n;
float x, S, T;
long M, N;
printf("\nNhap x: ");
scanf("%f", &x);
do
{
printf("\nNhap n(n >= 1) : ");
scanf("%d", &n);
if(n < 1)
{
printf("\n N phai >= 1. Xin nhap lai !");
}

}while(n < 1);

S = 1 + x;
N = 1;
i = 1;

while(i <= n)
{
T = pow(x, (2 * i + 1));
M = i * 2 + 1;
N = N * M * (M - 1);
S = S + T/N;
i++;
}
printf("\nTong la %f", S);
getch();
return 0;
}
reply
posted by bangtran on Jan 22
cách khác của mình:

int main()
{
int n, x, i, j;
unsigned long t1, t2;
float S;
i = 1;
j = 1;
S = 1;
cout << "Enter x, n: ";
cin >> x >> n;
t1 = x;
t2 = 1;
while (i <= n+1)
{
S = S + (float) t1 / t2;
t1 = t1 * x * x;
j = i * 2;
t2 = t2 * j * (j + 1);
i++;

}

cout << "S = " << S;

// END MAIN
system("pause");
}
reply
posted by mouto9k on Nov 15
bạn cũng có thể tạo hàm giai thừa riêng rồi gọi nó ra.
// S=1,i=0;
T = pow(x, (2 * i + 1));
M=giaithua(2*i+1);
S+=T/M;
reply