-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path合数拆分质因数.c
94 lines (89 loc) · 1.21 KB
/
合数拆分质因数.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<conio.h>
#include<math.h>
int isprime(int x)
{
if (x < 2)
{
return 0;
}
if (x >= 2)
{
for (int i = 2; i <= sqrt(x); i++)
{
if (x % i == 0)
{
return 0;
}
}
return 1;
}
}
void divide_number(int x)
{
int i = 2;
while(1)
{
if (isprime(i))
{
if (x % i == 0)
{
printf("%d*", i);
x = x / i;
if (isprime(x))
{
printf("%d", x);
}
else
{
divide_number(x);
}
break;
}
if (i >= x)
{
break;
}
}
i++;
}
}
int main()
{
loop:
{
int a;
printf("请输入一个合数:\n");
scanf("%d", &a);
if (isprime(a)||a<2)
{
printf("该数字是不是一个合数,请重新输入!\n");
goto loop;
}
else
{
printf("%d=", a);
divide_number(a);
printf("\n");
rechoose:{
printf("请按相应按键以继续或关闭程序:\n");
printf("**空格.退出程序**\n");
printf("**enter.继续输入**\n"); }
char a = _getch();
if (a == ' ')
{
printf("已退出!\n");
return 0;
}
else if(a==13) {
goto loop;
}
else {
printf("选择错误!请重新选择。\n");
goto rechoose;
}
}
return 0;
}
}