[ create a new paste ] login | about

Link: http://codepad.org/lmRN93rH    [ raw code | output | fork | 2 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 >= 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 + 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 incarnation16 on May 22
#include <stdio.h>

int main()
{
int n;
do
{

printf("Enter n: ");
scanf("%d", &n);

} while (n < 1);

int x;
printf("Enter x: ");
scanf("%d", &x);

int T = 1;
float sum = 1;
int M = 1;
float K;

for (int i = 1; i <= n; i++)
{

T = T * x * x;
K = i * 2;
M = M * K * (K - 1);

sum = sum + (float)T/M;
}
printf("Sum = %.2f", sum);
}
reply
posted by LeHoangAn on Aug 25
#include <iostream>
using namespace std;

int giaithua(int n) {
if (n == 1)
return 1;
return
n * giaithua(n - 1);
}

int main() {
int n, i;
double S, x;
cin >> x;
do
{
cin >> n;
if (n < 1)
cout << "n lon hon 1";
} while (n < 1);
S = 1;
i = 1;
while (i <= n) {
S = S + pow(x, 2 * i) / giaithua(2 * i);
i++;
}
cout << S;
return 0;
}
reply