
17.12.2007, 03:11
|
|
Новичок
Регистрация: 18.05.2007
Сообщений: 28
Провел на форуме: 133678
Репутация:
20
|
|
Пишу прямо в окне форума, потому может быть +/-:
Код:
#include <iostream.h>
#include <math.h>
int mypow(int a, int b)
{
if(b==0) return 1;int res=1;
for(int i=0;i<b;i++) res*=a;
return res;
}
int fact(int n)
{
if(n==0)return 1;
return n*fact(n-1);
}
void main()
{
cout << "Zada4a 1" << endl;
int n;double x;
cout << "Input N: "; cin >> n; cout << endl;
cout << "Input X: "; cin >> x; cout << endl << "------------"<<endl;
double res=0;
for(int i=0;i<n;i++)
{
res += mypow( -1, i) * ( mypow(x, 2*i)/fact(2*i) );
}
cout << "Result: "<<res;
}
|
|
|