[ create a new paste ] login | about

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

C, pasted on Aug 17:
#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);

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

	while(i <= n)
	{
		//T = T * x * x;
		T = pow(x, (2 * 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 dangtiendat86@gmail.com on Feb 1
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
float x,s=0;
cout<<"Nhap x="; cin>>x;
cout<<"Nhap n="; cin>>n;
for (int i=1; i<=n;i++) s+=(float)pow(x,2*i);
cout<<"kq="<<s<<endl;
}
reply