[ create a new paste ] login | about

Link: http://codepad.org/vv9VxA0R    [ raw code | output | fork | 5 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 >= 0) : ");
	scanf("%d", &n);
	  if(n < 0)
	  {
		  printf("\n N phai >= 0. Xin nhap lai !");
	  }

	}while(n < 0);

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

	while(i <= n)
	{
		T = pow(x, (2 * i ));
		M = i * 2;
		N = N * M * (M - 1);
		S = S + pow(-1, (float)i) * 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 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;
M *= K*(K-1);

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

}
cout<<"Sum= "<<S<<
endl;
cin.ignore();
return 0;
}
reply
posted by yonnon on Jul 12
Code mẫu bị vấn đề. Đề bài nói là mũ n+1 nhưng mẫu chỉ làm mũ N
reply
posted by cuong.luucb8921 on Aug 28
#include<stdio.h>

int main(){
int n;
float x;

do
{
printf("Nhap vap n:\n");
scanf("%d",&n);
if(n < 1)
{
printf("n phai lon hon bang 1\n");
}
}while(n < 1);

do
{
printf("Nhap vap x:\n");
scanf("%f",&x);
if(x == 0)
{
printf("x phai khac o\n");
}
}while(x == 0);

int i;
int t=1;
float sum=-1;

for(i=1;i<=n;i++)
{
t = t * (2*i) * (2*i-1);
sum = sum + (pow(-1,i+1)*pow(x,2*i))/t;
}

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


reply
posted by Nguyenhoai on Oct 5
-1+x^2/3!_x^4/5!+x^6/7!+.....+(-1)^n. X^2n/(2n+1)!
reply
posted by dattndev@gmail.com on Jan 31
#include <iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
double x,n,s=-1,tmp=1;
cout <<"Enter x: ";
cin >> x;
cout <<"Enter n: ";
cin >> n;
for(int i = 1; i <= n ; i++){

tmp *= (2*i)*(2*i-1);
s += (pow(-1,i+1)*pow(x,2*i))/ tmp;
}
cout << s;
return 0;
}
reply