C语言求完数因子
C语言求完数因子我想输出的格式比如6isfactorsare1,2,328isfactorsare,,,,,496is,,,,,,...
C语言求完数因子我想输出的格式比如6 is factors are 1,2,3
28 is factors are ,,,,,
496 is ,,,,,, 展开
28 is factors are ,,,,,
496 is ,,,,,, 展开
1个回答
展开全部
#include<stdio.h>
int a[110];
int main()
{
int sum=0,i,n,j,sizes;
printf("输入一个数:");
scanf("%d",&n);
for(i=1; i<=n; i++)
{
sum=0,sizes=0;
for(j=1; j<i; j++)
{
if(i%j==0)
{
sum+=j;
a[++sizes]=j;
}
}
if(sum==i)
{
printf("%d is factors are:",i);
for(j=1;j<=sizes;j++)
printf(j==sizes?"%d.\n":"%d,",a[j]);
}
}
return 0;
}
开个数组储存一下因子即可。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询