[ create a new paste ] login | about

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

C, pasted on Aug 17:
#include<stdio.h>
#include<conio.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;
		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 dongthevo on Aug 17
#include<iostream>
#include<cmath>
using namespace std;
int main()
{ //Tính S(n) = x + x^2 + x^3 + … + x^n
int x,n,S=0,dem=1;
for(;S==0;S=0,dem=1)
{
cout<<"Nhap x,n:";
cin>>x>>n;
for(;dem<=n;++dem)
{
S=S+pow(x,dem);
}
cout<<"S="<<S;
cout<<endl;
}
return 0;
}
reply