求根号m1
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
using namespace std;
int main()
{
double m;
cin >> m;
cout << sqrt(m);
getchar();
}
double ABS(double x)
{
return x < 0 ? x*-1 : x;
}
double sqrt(double m) {
double g = m;
while ( ABS(g*g - m )> 0.0000001)
{
g = (g + m / g) / 2;
}
return g;
}
最大公约数1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using namespace std;
int main()
{
int m, n,r;
cin >> m >> n;
while (n!=0)
{
r = m%n;
m = n;
n = r;
}
cout << m;
system("pause");
}
gcd(m,n) min{m,n}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
49
50
51
52
53
54
55
56
57
using namespace std;
int get_prime(int x)
{
int tmp = 0;
int i = 0;
int j = 0;
int k = 0, d;
int a[10] = { 0 };
d = x;
tmp = d;
//遍历2到d中的所有数,先判断该数是否为素数,再判断该数是否为d的因数,两个条件满足则将其存入数组中;否则进行下一次循环* /
for (i = 2; i <= d; i++)
{
//判断该数是否为素数,若非素数则进行下一次循环
for (j = 2; j<i; j++)
{
if (i % j == 0)
{
break;
}
}
//判断i是否为d的因数,如果是则将i存入临时数组,并更新d的值,此处用while是为了满足一个整数中有几个相同的因数的情况
while (d % i == 0)
{
a[k++] = i;
d = d / i;
}
}
//分三段将该数组打印到终端
printf("%d=", tmp);
for (i = 0; i<k - 1; i++)
{
printf("%d*", a[i]);
}
printf("%d\n", a[k - 1]);
return 0;
}
int get_comment_prime()
{
return 0;
}
int main()
{
int m, n;
printf("please input a data:");
cin >> m>>n;
get_prime(m);
get_prime(n);
cout<<get_comment_prime();
system("pause");
}