2
编一程序 对于用户输入的任意正偶数n 将其分解成两素数之和
#include<stdio.h>
#include<conio.h>
#include<math.h>
void XUNHUAN(int number);
int PANDUANSUSHU(int number_1);
void main()
{
int integer;
printf("Input an integer:");
scanf("%d",&integer);
XUNHUAN(integer);
getch();
}
void XUNHUAN(int number)
{
int a_number,b_number;
for(a_number=2;a_number<number;a_number++){
if(PANDUANSUSHU(a_number)==1){
b_number=number-a_number;
if(PANDUANSUSHU(b_number)==1&&b_number>1&&a_number<=b_number)
printf("%-5d%-5d\n",a_number,b_number);
}
}
}
int PANDUANSUSHU(int number_1)
{
int i;
for(i=2;i<sqrt(number_1);i++)
if(number_1%i==0)
break;
if(i>sqrt(number_1))
return 1;
else
return 0;
}