Solution Of Class B
Post date: May 13, 2013 7:57:43 PM
#include <iostream>
#include <fstream>
using namespace std;
double power(int x,int y)
{
int p = 1;
for (int i = 0; i < x; i++)
p *= y;
return p;
}
void main()
{
int i;
cout<<"Enter '1' for odd."<<endl;
cout<<"Enter '2' for even."<<endl;
cin>>i;
cout<<"Enter n : ";
int n;
cin>>n;
double sum = 0;
for (i; i <= n; i+=2)
sum += (1/power(i, i));
cout << "Result = " << sum << endl;
ofstream oFile;
oFile.open("result.txt");
oFile << "Result = " << sum << endl;
oFile.close();
system ("pause");
}