|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include<stdio.h>
- //质因子分解
- int main(void)
- {
- int num,i=2,temp,first_num=1;
- scanf("%d",&num);
- temp=num;
- while(temp)
- {
- while(temp&&temp%i==0)
- {
- if(first_num)
- {
- printf("%d",i);
- first_num=0;
- }
- else
- {
- printf("*%d",i);
- }
- temp/=i;
- }
- i++;
- }
- return 0;
- }
复制代码
本帖最后由 jackz007 于 2021-9-25 20:19 编辑
- #include<stdio.h>
- int main(void)
- {
- int num , i = 2 , temp , first_num = 1 ;
- scanf("%d" , & num) ;
- temp = num ;
- while(temp && i <= temp)
- {
- if(temp && temp % i == 0)
- {
- if(first_num)
- {
- printf("%d",i);
- first_num=0;
- }
- else
- {
- printf("*%d",i);
- }
- temp /= i ;
- } else {
- i ++ ;
- }
- }
- return 0;
- }
复制代码
编译、运行实况
- D:\00.Excise\C>g++ -o x x.c
- D:\00.Excise\C>x
- 6
- 2*3
- D:\00.Excise\C>x
- 60
- 2*2*3*5
- D:\00.Excise\C>x
- 240
- 2*2*2*2*3*5
- D:\00.Excise\C>x
- 1680
- 2*2*2*2*3*5*7
- D:\00.Excise\C>x
- 113
- 113
- D:\00.Excise\C>
复制代码
|
|