[ create a new paste ] login | about

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

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
posted by lagi_an@yahoo.com.vn on Aug 30
#include<stdio.h>
#include<math.h>
int main(){
int x,n,i;
int sum=0;
printf("hay nhap gia tri cua x");
scanf("%d",&x);
printf("hay nhap gia tri cua n");
scanf("%d",&n);
for(i=1;i<=n;i++){
sum+=pow(x,i);
}
printf("vay gia tri cua cap so cong la %d ",sum);

return 0;
}


reply