02.10.2013, 12:52. Просмотров 1837. Ответов 20
Вот есть программа, работает только, для положительной степени. Помогите разобрать что не так? pow не предлагать!
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
| #include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int x, y, res = 1;
cout << "Enter digits x, y:" << endl;
cin >> x;
cin >> y;
if (x==0)
{
cout << "0" << endl;
}
else
{
if (x==1)
{
cout << "1" << endl;
}
else
{
if (y==0)
{
cout << "1" << endl;
}
else
{
if (y<0)
{
res = 1/res;
}
else
{
int i=1;
do
{
res=res*x;
++i;
}
while (i<=y);
cout << res << endl;
}
}
}
}
system("pause");
return 0;
} |
|