[ create a new paste ] login | about

Link: http://codepad.org/ogiGkP5t    [ raw code | output | fork | 1 comment ]

C, pasted on Aug 31:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
	int i, n;
	float x, T, S;
	i = 1;
	T = 1;
	S = 0;
	printf("\nNhap x: ");
	scanf("%f", &x);
	//x = -x;
	printf("\nNhap n: ");
	scanf("%d", &n);

	while(i <= n)
	{
		T = pow(x, (2 * i )) * pow(-1, (float)i);
		S = S + T;
		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 maiphu.2510@gmail.com on Aug 14
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
float x,s=0;
int n;

printf("\nNhap x = ");
scanf("%f",&x);
printf("\nNhap n = ");
scanf("%d",&n);
for(int i=2;i<=(2*n);i+=2)
{
s=s + ( - ( pow(x,i)));
if(i<2*n)
{
i+=2;
s = s + ( pow(x,i));
}
}
printf("\n tong la %f",s);
getch();
return 0;
}
reply