㈠ 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;
}