c语言分解100,用C语言实现,将100之内的自然数分解质因数

用C语言实现,将100以内的自然数分解质因数

使用C语言,编写代码,实现100以内的自然数分解质因数

------解决方案--------------------

#include

#include

int fenjie(int n)

{

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

{

if(n%i==0)

{

printf("%d*",i);

return fenjie(n/=i);

break;

}

}

return printf("%d\n",n);

}

int main()

{

int num;

while(scanf("%d",&num)!=EOF)

fenjie(num);

return 0;

}

------解决方案--------------------

任意输入一个整数,将这个整数进行质因数分解n(2<=n<=100000000);

------解决方案--------------------

Finding prime numbers - Kenneth Haugland

Different schemas for finding prime numbers explained with code

http://www.codeproject.com/Article.aspx?tag=198374988322054872&

------解决方案--------------------

仅供参考,尽管是C#

//******************************************************************************

// Author           :   Alexander Bell

// Copyright        :   2007-2011 Infosoft International Inc

// Date Created     :   01/15/2007

// Last Modified    :   02/08/2011

// Description      :   Prime Factoring

//******************************************************************************

// DISCLAIMER: This Application is provide on AS IS basis without any warranty

//******************************************************************************

//******************************************************************************

// TERMS OF USE     :   This module is copyrighted.

//                  :   You can use it at your sole risk provided that you keep

//                  :   the original copyright note.

//******************************************************************************

using System;

using System.Collections.Generic;

namespace Infosoft.MathShared

{

/// Integers: Properties and Operations

public  static partial class Integers

{

#region Prime Numbers <100

private static readonly int[] Primes =

new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23,

29, 31, 37, 41, 43, 47, 53, 59,

61, 67, 71, 73, 79, 83, 89, 97 };

#endregion

// starting number for iterative factorization

private const int _startNum = 101;

#region IsPrime: primality Check

/// 

/// Check if the number is Prime

/// 

/// Int64

/// bool

public static bool IsPrime(Int64 Num){

int j;

bool ret;

Int64 _upMargin = (Int64)Math.Sqrt(Num) + 1; ;

// Check if number is in Prime Array

for (int i = 0; i 

if (Num == Primes[i]) { return true; }

}

// Check divisibility w/Prime Array

for (int i = 0; i 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值