Solution Of Class B

posted May 13, 2013, 12:57 PM by Salah Ibrahim   [ updated May 13, 2013, 12:57 PM by Karwan Jacksi ]
#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");
}
Comments