雾山五行


私信TA

用户名:uq_26515002996

访问量:742

签 名:

等  级
排  名 11001
经  验 1055
参赛次数 0
文章发表 14
年  龄 0
在职情况 在职
学  校
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

                                                    #include <stdio.h>

                                                    int main(){

                                                                 int n;

                                                                 int num=0,c=0;

                                                                 int s[100];

                                                                

                                                                 scanf("%d",&n);

                                                                 for(int i=2;i<=n;i++){  

                                                                         num=0;  //记录因数和

                                                                         c=0;  //记录因数个数

                                                                         for(int j=1;j<=i/2;j++){   //一个数除它本身外最大因数是它的二分之一

                                                                                 if(i%j==0){

                                                                                         num+=j;

                                                                                         s[c]=j;

                                                                                         c++;

                                                                                 }

                                                                         }

                                                                         if(i==num){  //因数和与此数相等,输出数据

                                                                                 printf("%d its factors are",i);   //前面的字符串先输出

                                                                                 for(int f=0;f<c;f++){   //因数循环输出

                                                                                         printf(" %d",s[f]);

                                                                                 }

                                                                                 putchar('\n');

                                                                         }

                                                                 }

                                                                 return 0;

                                                    }


 

0.0分

0 人评分

  评论区

  • «
  • »