㈠ java編程:求解1到100間的合數之和,高手幫忙.
public class text {
public text() {
}
private int getSum()
{
int sum = 0;
for(int i=2;i<=100;i++)
{
if(!this.isPrimeNumber(i))
sum += i; //是合數則累加
}
return sum;
}
/**
*判斷是否是合數
*/
private boolean isPrimeNumber(int number)
{
for(int i=2;i<number;i++)
{
if(number%i == 0)
return false;
}
return true;
}
public static void main(String[] args) {
text text = new text();
System.out.println("1-100的合數的和是:"+text.getSum());
}
}
㈡ c語言編程:合數分解
#include<stdio.h>
intmain()
{inti,k,n;
scanf("%d",&n);
for(i=2;i*i<=n;i++)
if(n%i==0)
{k=0;
while(n%i==0){k++;n/=i;}
if(k>1)printf("%d",i);
}
printf("
");
return0;
}