您的位置:首页 > 其它

分解质因数

2015-12-25 21:02 387 查看
</pre><pre name="code" class="html">//输入一个数,分解质因数
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
@autoreleasepool {
int x;
int i;

scanf("%d",&x);
printf("%d = ",x);

for (i = 2; i <= x; i++)
{
if (x % i == 0 )
{
x = x / i;
printf("%d",i);
if (x == 1)
{
break;
}
i--;
printf(" x ");
}
}
printf("\n");
}
return 0;
}
//结果:
//56
//56 = 2 x 2 x 2 x 7
//Program ended with exit code: 0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: