輸入一正數求它包含的最大質數
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int x,i,j,prime,biggest;
do{
printf("Please enter a positive number:\n");
scanf("%d",&x);
}while(x<=0);
for(i=2;i<=x;i++) {
prime = 1;
for(j=2;j<=i/2;j++) {
if(i%j==0) {
prime=0;
break;}
}
if(prime==1) biggest=i;
}
printf("The biggest prime for %d is %d.\n",x,biggest);
return 0;
}
|