
13.11.2008, 00:01
|
|
Постоянный
Регистрация: 08.04.2007
Сообщений: 853
Провел на форуме: 5812656
Репутация:
1540
|
|
Код:
// lab1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
int fact(int); //факториал
int _tmain(int argc, _TCHAR* argv[])
{
int a,b,n;
//Ввод
cout<<"Enter a:";
cin>>a;
cout<<"Enter b:";
cin>>b;
cout<<"Enter n:";
cin>>n;
//Условия
if(b>5) b=4;
if(a<2) a=2;
int s = 0; //сумма
//Суммируем
for(int i=0;i<n;i++)
{
s += (pow((double)(a*b),(double)i-1))/(fact(i)*(b-i));
}
cout<<"Answer:"<<s;
return 0;
}
int fact(int a)
{
if(a==0) return 1;
else return a*fact(a-1);
}
|
|
|