码迷,mamicode.com
首页 > 其他好文 > 详细

90=2x3x3x5

时间:2015-07-31 22:05:40      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

/*将一个正整数分解质因数如90=2x3x3x5*/
#include<stdio.h>
#define L 5
int qualityfun(int intnum);
int main(int argc, char *argv[])
{
	int integer, i, j;
	i = j = integer = 0;
	//int quality[L] = {2,3,5,7,11};
	int answer[2*L] = {0};
	scanf("%d", &integer);
	printf("%d=", integer);
	for(i=1;integer!=1;i++)
	{
		if(qualityfun(i)==0) continue;
		while(integer%i==0&&integer!=1)
		{
			answer[j++]=i;
			integer /=i;
		}
	}
	for(i=0;i<j;i++)
	{
		if(i>0) putchar(‘x‘);
		printf("%d", answer[i]);
	}
	putchar(‘\n‘);
	return 0;
}


int qualityfun(int intnum)
{
	int i, judge;
	intnum = intnum==1 ? 0 : intnum;
	for(judge=1,i=2;i<intnum;i++)
	{
		if(intnum%i==0)
		{
			intnum=judge=0;
			break;
		}
	}
	if(judge==1)
		return intnum;
	else
		return intnum;
}



90=2x3x3x5

标签:

原文地址:http://my.oschina.net/dengwo/blog/486315

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!