[ create a new paste ] login | about

Link: http://codepad.org/UcmmIGBm    [ raw code | output | fork | 3 comments ]

C, pasted on Aug 31:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
	int i, n;
	float x, T, S;
	i = 0;
	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 + 1)) * 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 yonnon on Jul 12
#include<bits/stdc++.h>

using namespace std;
int main(){
float x;
int n;
cout <<"Enter x= ";
cin >> x;
cout << "Enter n= ";
cin >> n;
float S=0;
for(int i=0; i<n; ++i){
S+= pow(-1,static_cast<float>(i))*pow(x,(2*i+1));

}
cout<<"Sum= "<<S<<
endl;
return 0;
}
reply
posted by pmt290801 on Nov 10
for(int i=0; i<=n; ++i)
reply
posted by pmt290801 on Nov 10
#include<bits/stdc++.h>

using namespace std;
int main(){
float x;
int n;
cout <<"Enter x= ";
cin >> x;
cout << "Enter n= ";
cin >> n;
float S=x;
for(int i=1; i<=n; i++){
S+= pow(-1,static_cast<float>(i))*pow(x,(2*i+1));

}
cout<<"Sum= "<<S<<
endl;
return 0;
}

reply