[ create a new paste ] login | about

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

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
posted by NHDARES on Feb 29
#include <stdio.h>
#include <stdlib.h>
int S(int a,int b);
int main()
{
int a=0;
int b=0;
printf("nhap a,b:\n");
scanf("%d%d",&a,&b);
printf("%d",S(a,b));

}

int S(int a,int n)
{

int Tong=0;
int SoThayThe=a;
if(n==0)
Tong=0;
if(n==1)
return a;
int i=1;
while(i<=n)
{
if(i%2==1||i==1)
{
Tong=Tong+a;
}
a=a*SoThayThe;
i++;
};
return Tong;
}

reply
posted by lagi_an@yahoo.com.vn on Aug 30
int main(){
int x,n;
int 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++){
if(i%2==0)
sum+=pow(x,n);}
printf("%d",sum);

return 0;
}


reply
posted by 20223768 on Sep 9
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int n; cin >>n;
int x; cin >>x;
int s=0;
for (int i=0; i<n; i++)
{
s=s+pow(x,2*i);
}
cout << s;
return 0;
}
reply