因子分解

时间:2021-04-14 11:57:55   收藏:0   阅读:0

输入一个数,分解成其质因子

 1 #include<stdio.h>
 2 
 3 int main()
 4 {
 5     int val,temp;
 6     scanf("%d", &val);
 7     printf("%d=1*", val);
 8     temp = val;
 9     for (int i = 2; i < val;i++)
10     {
11         while(temp % i == 0)
12         {
13             temp = temp / i;
14             printf("%d", i);
15             if (temp > 1)
16             {
17                 printf("*");
18             }
19         }
20     }
21     return 0;
22 }

temp用来取余,val用来控制循环次数

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!