[ create a new paste ] login | about

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

C, pasted on Aug 31:
#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 + pow(-1, (float)(i + 1)) * T/N ;
		i++;
	}
	printf("\nTong la %f", S - 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 tothanh10061997 on May 1
s= 1 +x^3/3!-..+.. ko co -x sai roi

reply
posted by yonnon on Jul 12
#include<bits/stdc++.h>

using namespace std;
int main(){
int n;
int x;
cout <<"Enter x= ";
cin >> x;
cout << "Enter n= ";
cin >> n;
int K=1;
int M=1;
float S=0;
for(int i=1 ; i<=n ; ++i){
K=2*i+1;
M *= K*(K-1);

S += pow(-1.0,i+1) * (pow(static_cast<float>(x),2.0*i+1)/(M));

}
cout<<"Sum= "<<S<<
endl;
cin.ignore();
return 0;
}
reply
posted by yonnon on Jul 12
bài này có thể mình làm sai.. tại lười ~
reply