鱼C论坛

 找回密码
 立即注册
查看: 981|回复: 1

[已解决]请问这个哪里有问题?

[复制链接]
发表于 2021-9-25 18:12:48 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. #include<stdio.h>
  2. //质因子分解
  3. int main(void)
  4. {
  5.    int num,i=2,temp,first_num=1;
  6.    scanf("%d",&num);
  7.    temp=num;
  8.    while(temp)
  9.    {
  10.        while(temp&&temp%i==0)
  11.        {
  12.            if(first_num)
  13.            {
  14.                printf("%d",i);
  15.                first_num=0;
  16.            }
  17.            else
  18.            {
  19.                printf("*%d",i);
  20.            }
  21.            temp/=i;
  22.        }
  23.        i++;
  24.    }
  25.     return 0;
  26. }
复制代码
最佳答案
2021-9-25 20:08:47
本帖最后由 jackz007 于 2021-9-25 20:19 编辑
  1. #include<stdio.h>

  2. int main(void)
  3. {
  4.    int num , i = 2 , temp , first_num = 1 ;
  5.    scanf("%d" , & num)                    ;
  6.    temp = num                             ;
  7.    while(temp && i <= temp)
  8.    {
  9.        if(temp && temp % i == 0)
  10.        {
  11.            if(first_num)
  12.            {
  13.                printf("%d",i);
  14.                first_num=0;
  15.            }
  16.            else
  17.            {
  18.                printf("*%d",i);
  19.            }
  20.            temp /= i ;
  21.        } else {
  22.            i ++ ;
  23.        }
  24.    }
  25.     return 0;
  26. }
复制代码

        编译、运行实况
  1. D:\00.Excise\C>g++ -o x x.c

  2. D:\00.Excise\C>x
  3. 6
  4. 2*3
  5. D:\00.Excise\C>x
  6. 60
  7. 2*2*3*5
  8. D:\00.Excise\C>x
  9. 240
  10. 2*2*2*2*3*5
  11. D:\00.Excise\C>x
  12. 1680
  13. 2*2*2*2*3*5*7
  14. D:\00.Excise\C>x
  15. 113
  16. 113
  17. D:\00.Excise\C>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-9-25 20:08:47 | 显示全部楼层    本楼为最佳答案   
本帖最后由 jackz007 于 2021-9-25 20:19 编辑
  1. #include<stdio.h>

  2. int main(void)
  3. {
  4.    int num , i = 2 , temp , first_num = 1 ;
  5.    scanf("%d" , & num)                    ;
  6.    temp = num                             ;
  7.    while(temp && i <= temp)
  8.    {
  9.        if(temp && temp % i == 0)
  10.        {
  11.            if(first_num)
  12.            {
  13.                printf("%d",i);
  14.                first_num=0;
  15.            }
  16.            else
  17.            {
  18.                printf("*%d",i);
  19.            }
  20.            temp /= i ;
  21.        } else {
  22.            i ++ ;
  23.        }
  24.    }
  25.     return 0;
  26. }
复制代码

        编译、运行实况
  1. D:\00.Excise\C>g++ -o x x.c

  2. D:\00.Excise\C>x
  3. 6
  4. 2*3
  5. D:\00.Excise\C>x
  6. 60
  7. 2*2*3*5
  8. D:\00.Excise\C>x
  9. 240
  10. 2*2*2*2*3*5
  11. D:\00.Excise\C>x
  12. 1680
  13. 2*2*2*2*3*5*7
  14. D:\00.Excise\C>x
  15. 113
  16. 113
  17. D:\00.Excise\C>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-26 04:03

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表